|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『楼 主』:
reg2bat
使用 LLM 解释/回答一下
看了最近的几个提问 reg2bat 的帖子,觉得写出来还是蛮实用的,昨晚写的,大家测试下
sed用的不好,感觉有很多垃圾代码,望大虾指点
sed下载:http://www.yx127.com/tools/gsed_407x.rar
@echo off
setlocal enabledelayedexpansion
title reg2bat by:vkill
::注意:注册表项中不可有=,项目、名字、数值中不可有"
::config
set "temp=temp_.txt"
set "life_b=bats_.bat"
:test
cls
if not *%1==* (set "life_r=%1") else (
echo 只支持单文件,多文件请使用*.reg
set life_r=
set /p life_r=请把要转化的reg文件拖到本窗口:
if %life_r%*==* goto test
)
call :000 %life_r%
goto :eof
:000
echo "%~1"|sed "s/\x22$//"|(findstr /E /I ".reg">nul ||(echo sorry要处理的不是reg文件&pause>nul&goto :eof))
if not exist "%~1" (echo sorry要处理reg文件不存在&pause>nul&goto :eof)
::去除.reg的表头和所有空格
if exist %temp%? del /f/q %temp%?
type "%~1"|sed -e "/^REGEDIT4$/d;/^Windows Registry Editor Version 5.00$/d;/^$/d" -e "y/
/d;/^.*=.*$/d" %temp%1|more>%temp%2
findstr . %temp%2>nul ||(copy /y %temp%1 %temp%3>nul &goto start_)
echo .reg文件中有错误,1秒后开始自动除错
ping -n 2 127.1>nul
sed -e "/^#HKEY_.*\.*]/b;/^.*=.*$/b" -e d %temp%1|more>%temp%3
echo 除错完成
:start_
:去除",并转换数据类型,可继续添加数据类型
sed -e "s/^#//;s/]$//" -e "s/\x22//g" %temp%3 |sed "s/=/=REG_SZ=/" |sed "s/=REG_SZ=dword:/=REG_DWORD=/;s/=REG_SZ=hex:/=REG_BINARY=/;s/=REG_SZ=hex(7):/=REG_MULTI_SZ=/;s/=REG_SZ=hex(2):/=REG_EXPAND_SZ=/" |sed "s/^*//;s/*$//" |sed "/^$/d"|more>%temp%4
::写日志
>>%life_b% echo :: %date% %time% 添加
::写reg add
for /f "tokens=1-3 delims==" %%a in (%temp%4) do (
if not *%%b==* (if not !xiang!*==* >>%life_b% echo reg add "!xiang!" /v "%%~a" /t %%~b /d "%%~c" /f) else (set "xiang=%%~a")
)
if exist %life_b% (
echo 正在删除%life_b%中的相同行
ren %life_b% %temp%5
sed -n "G; s/\n/&&/; /^\(*\n\).*\n\1/d; s/\n//; h; P" %temp%5 |more>%life_b%
echo %life_b%中的相同行删除完成
)
del /f/q %temp%?
echo ok %life_r%2bat转换完成,结果保存在了%life_b%文件中,程序1秒后自动退出
ping -n 3 127.1>nul
goto :eof
Last edited by vkill on 2006-11-21 at 09:31 AM ]
After looking at the recent few posts about reg2bat, I think it's quite practical when written out. I wrote it last night, everyone can test it.
The sed usage is not good, I feel there are a lot of garbage codes, hope the experts can give pointers.
Sed download: http://www.yx127.com/tools/gsed_407x.rar
@echo off
setlocal enabledelayedexpansion
title reg2bat by:vkill
::Note: There should be no = in the registry key, and no " in the item, name, and value.
::config
set "temp=temp_.txt"
set "life_b=bats_.bat"
:test
cls
if not *%1==* (set "life_r=%1") else (
echo Only single files are supported, for multiple files please use *.reg
set life_r=
set /p life_r=Please drag the reg file to be converted to this window:
if %life_r%*==* goto test
)
call :000 %life_r%
goto :eof
:000
echo "%~1"|sed "s/\x22$//"|(findstr /E /I ".reg">nul ||(echo sorry The file to be processed is not a reg file&pause>nul&goto :eof))
if not exist "%~1" (echo sorry The reg file does not exist&pause>nul&goto :eof)
::Remove the header of .reg and all spaces
if exist %temp%? del /f/q %temp%?
type "%~1"|sed -e "/^REGEDIT4$/d;/^Windows Registry Editor Version 5.00$/d;/^$/d" -e "y/
/d;/^.*=.*$/d" %temp%1|more>%temp%2
findstr . %temp%2>nul ||(copy /y %temp%1 %temp%3>nul &goto start_)
echo There are errors in the .reg file, automatic debugging will start in 1 second
ping -n 2 127.1>nul
sed -e "/^#HKEY_.*\.*]/b;/^.*=.*$/b" -e d %temp%1|more>%temp%3
echo Debugging completed
:start_
::Remove , ", and convert data types, can continue to add data types
sed -e "s/^#//;s/]$//" -e "s/\x22//g" %temp%3 |sed "s/=/=REG_SZ=/" |sed "s/=REG_SZ=dword:/=REG_DWORD=/;s/=REG_SZ=hex:/=REG_BINARY=/;s/=REG_SZ=hex(7):/=REG_MULTI_SZ=/;s/=REG_SZ=hex(2):/=REG_EXPAND_SZ=/" |sed "s/^*//;s/*$//" |sed "/^$/d"|more>%temp%4
::Write log
>>%life_b% echo :: %date% %time% added
::Write reg add
for /f "tokens=1-3 delims==" %%a in (%temp%4) do (
if not *%%b==* (if not !xiang!*==* >>%life_b% echo reg add "!xiang!" /v "%%~a" /t %%~b /d "%%~c" /f) else (set "xiang=%%~a")
)
if exist %life_b% (
echo Deleting the same lines in %life_b%
ren %life_b% %temp%5
sed -n "G; s/\n/&&/; /^\(*\n\).*\n\1/d; s/\n//; h; P" %temp%5 |more>%life_b%
echo The same lines in %life_b% have been deleted
)
del /f/q %temp%?
echo ok %life_r%2bat conversion completed, the result is saved in the %life_b% file, the program will automatically exit in 1 second
ping -n 3 127.1>nul
goto :eof
Last edited by vkill on 2006-11-21 at 09:31 AM ]
此帖被 +7 点积分 点击查看详情 评分人:【 redtek 】 | 分数: +2 | 时间:2006-11-20 07:12 | 评分人:【 lxmxn 】 | 分数: +3 | 时间:2006-11-20 07:38 | 评分人:【 flyinspace 】 | 分数: +2 | 时间:2007-4-30 05:41 |
|
|
|
2006-11-20 07:09 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
希望有用,呵呵 ~支持*.bat
Last edited by vkill on 2006-11-20 at 07:10 AM ]
Hope it's useful, heh heh ~ Supports *.bat
Last edited by vkill on 2006-11-20 at 07:10 AM ]
|
|
2006-11-20 07:09 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
reg2bat的关键不在于reg的格式,而是在于reg的键值类型。
记得上次我转过一贴,上面就详细地描述了不同类型键值的表示方式。
只有能把下面几种类型的键值还原,那么才能真正地实现reg2bat:
0 reg_none
1 reg_sz
2 reg_expand_sz
3 reg_binary
4 reg_dword, reg_dword_little_endian
5 reg_dword_big_endian
6 reg_link
7 reg_multi_sz
8 reg_resource_list
9 reg_full_resource_descriptor
10 reg_resource_requirements_list
如果要纯粹地通过批处理来完成的话,建议用查表的方式来实现。例如下面是一个把ip地址置换为hex(7)类型的脚本,没有出错处理,且只能处理ip地址:
@echo off
setlocal ENABLEDELAYEDEXPANSION
:start
set /p intIP=输入IP:
for /l %%i in (0,1,14) do (
set str=!intIP:~%%i,1!
if not "!str!" == "" (
if not "!str!" == "." (
set strIP=!strIP!3!str!,00,
) else (
set strIP=!strIP!2e,00,
)
)
)
set "strIP="IPAddress"=hex(7):%strIP%00,00,00,00"
if "%strIP:~76,1%" == "," echo %strIP:~0,77%\ && echo %strIP:~77%
if "%strIP:~77,1%" == "," echo %strIP:~0,78%\ && echo %strIP:~78%
if "%strIP:~78,1%" == "," echo %strIP:~0,79%\ && echo %strIP:~79%
if "%strIP:~80,1%" == "" echo %strIP%
pause
goto :eof
太久以前写的,现在看来代码很不成熟,发出来做个参考吧。
The key of reg2bat is not in the format of reg, but in the key value type of reg.
I remember that last time I transferred a post, which described in detail the representation methods of different types of key values.
Only when the key values of the following several types can be restored, can reg2bat be truly realized:
0 reg_none
1 reg_sz
2 reg_expand_sz
3 reg_binary
4 reg_dword, reg_dword_little_endian
5 reg_dword_big_endian
6 reg_link
7 reg_multi_sz
8 reg_resource_list
9 reg_full_resource_descriptor
10 reg_resource_requirements_list
If it is to be completed purely through batch processing, it is recommended to implement it in the way of looking up a table. For example, the following is a script that replaces the IP address with hex(7) type, without error handling, and can only handle the IP address:
@echo off
setlocal ENABLEDELAYEDEXPANSION
:start
set /p intIP=Input IP:
for /l %%i in (0,1,14) do (
set str=!intIP:~%%i,1!
if not "!str!" == "" (
if not "!str!" == "." (
set strIP=!strIP!3!str!,00,
) else (
set strIP=!strIP!2e,00,
)
)
)
set "strIP="IPAddress"=hex(7):%strIP%00,00,00,00"
if "%strIP:~76,1%" == "," echo %strIP:~0,77%\ && echo %strIP:~77%
if "%strIP:~77,1%" == "," echo %strIP:~0,78%\ && echo %strIP:~78%
if "%strIP:~78,1%" == "," echo %strIP:~0,79%\ && echo %strIP:~79%
if "%strIP:~80,1%" == "" echo %strIP%
pause
goto :eof
Written a long time ago, now it seems that the code is very immature, and it is posted for reference.
|
|
2006-11-20 13:34 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
3742668斑竹
sed "s/=/=REG_SZ=/" |sed "s/=REG_SZ=dword:/=REG_DWORD=/;s/=REG_SZ=hex:/=REG_BINARY=/;s/=REG_SZ=hex(7):/=REG_MULTI_SZ=/;s/=REG_SZ=hex(2):/=REG_EXPAND_SZ=/"
上面这段就是判断reg的键值类型并还原的哦
Last edited by vkill on 2006-11-21 at 09:49 AM ]
3742668 moderator
sed "s/=/=REG_SZ=/" |sed "s/=REG_SZ=dword:/=REG_DWORD=/;s/=REG_SZ=hex:/=REG_BINARY=/;s/=REG_SZ=hex(7):/=REG_MULTI_SZ=/;s/=REG_SZ=hex(2):/=REG_EXPAND_SZ=/"
The above paragraph is to judge the key value type of reg and restore it.
Last edited by vkill on 2006-11-21 at 09:49 AM ]
|
|
2006-11-21 09:08 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
我测试的时候是导出reg来试验的哦
I tested by exporting the reg to experiment, oh
|
|
2006-11-21 09:37 |
|
|
qpmgljf
初级用户
 
积分 125
发帖 49
注册 2006-12-24
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
楼主啊。。。。不行。。。。。拖进去后什么也不显示。拖别的文件也不显示。都是只显示一个拖进去的文件的路径而已啊。。。。
能再编一下吗?急用哦。~~~~
Lz楼主 ah... no good... after dragging in, nothing is displayed. Dragging other files also doesn't display. It just shows the path of the dragged-in file... Can you edit it again? Urgent oh.~~~~
|
|
2007-1-8 04:47 |
|
|
yxii001
新手上路

积分 18
发帖 9
注册 2007-1-14
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
楼主
第一次拖进去没用,第二次就退出了,期间无任何提示
The first time I dragged it in, it didn't work. The second time, it exited, and there were no prompts during that period.
|
|
2007-1-17 23:44 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by qpmgljf at 2007-1-7 15:47:
楼主啊。。。。不行。。。。。拖进去后什么也不显示。拖别的文件也不显示。都是只显示一个拖进去的文件的路径而已啊。。。。
能再编一下吗? ...
好像是%life_r%变量部分位置没做好双引号,造成包含空格的目录出错
Originally posted by qpmgljf at 2007-1-7 15:47:
楼主啊。。。。不行。。。。。拖进去后什么也不显示。拖别的文件也不显示。都是只显示一个拖进去的文件的路径而已啊。。。。
Can you recompile it? ...
It seems that the double quotes in the %life_r% variable part were not properly placed, causing errors with directories containing spaces
|
|
2007-1-17 23:55 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Originally posted by zh159 at 2007-1-17 23:55:
好像是%life_r%变量部分位置没做好双引号,造成包含空格的目录出错
哎,今天我才发现,超级错误啊
Originally posted by zh159 at 2007-1-17 23:55:
It seems that the double quotes in the %life_r% variable part were not properly placed, causing errors with directories containing spaces.
Hey, I just realized today, it's a super big mistake!
|
|
2007-1-18 08:35 |
|
|
bingxiao20
初级用户
 
积分 68
发帖 31
注册 2007-3-23
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
这个有修改好么?就是那个变量那里。。
Is this modified? It's about that variable.
|
|
2007-4-30 02:46 |
|
|
ghost2008
新手上路

积分 12
发帖 6
注册 2006-7-13
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
改成这个就行啦,输入你想转换的REG文件一秒就生成BAT文件,用下来,百分百实用
@echo off
:manu
cls
echo.
echo 请输入要转换的注册表文件名(完整路径):
set object=
set /p object=
echo %object%|find /i ":" && goto :do
echo.
echo 错误!要求输入完整的路径和注册表文件名!
echo.
echo 例如:D:\soft\anti.reg
echo.
echo 任意键返回重新输入……
pause>nul
cls
goto manu
:do
echo.
for /f "tokens=*" %%a in ('type %object%') do echo echo %%a^>^>temp1234.reg>>%object%.bat
echo regedit /s temp1234.reg>>%object%.bat
echo del /f /q /a temp1234.reg>>%object%.bat
echo.
echo 已经转换成%object%.bat!任意键退出……
pause>nul
exit
Just change it to this. Enter the REG file you want to convert and it will generate a BAT file in one second. It's 100% practical after using it.
@echo off
:manu
cls
echo.
echo Please enter the name of the registry file to convert (full path):
set object=
set /p object=
echo %object%|find /i ":" && goto :do
echo.
echo Error! The full path and registry file name are required!
echo.
echo For example: D:\soft\anti.reg
echo.
echo Press any key to return and re-enter...
pause>nul
cls
goto manu
:do
echo.
for /f "tokens=*" %%a in ('type %object%') do echo echo %%a^>^>temp1234.reg>>%object%.bat
echo regedit /s temp1234.reg>>%object%.bat
echo del /f /q /a temp1234.reg>>%object%.bat
echo.
echo Has been converted to %object%.bat! Press any key to exit...
pause>nul
exit
|
|
2007-9-10 11:17 |
|
|
hdzc
初级用户
 
积分 146
发帖 86
注册 2007-10-1
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
『第 11 楼』ghost2008
发的很好用
Post by ghost2008 on the 11th floor: Very useful
|
|
2007-10-27 08:51 |
|
|
dato
高级用户
   
积分 916
发帖 377
注册 2004-3-8
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
ghost2008这种方式
其实以前在实现桌面时用regedit /s命令但这个命令在受限的user却会提示权限问题用reg add方式又没问题,
The method of ghost2008
Actually, I used the regedit /s command when implementing the desktop before, but this command will prompt a permission issue for restricted users, while the reg add method has no problem.
|

http://dato.ys168.com
google search bot
http://dato.minidns.net/ |
|
2007-10-27 12:56 |
|
|
freesoft00
新手上路

积分 4
发帖 2
注册 2006-9-25
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
vkill把你的代码修正一下吧。我不会。
vkill, please correct your code for me. I don't know how.
|
|
2007-11-28 15:00 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by freesoft00 at 2007-11-28 15:00:
vkill把你的代码修正一下吧。我不会。
我觉得还是用reg2inf吧,那个没有是么bug
Originally posted by freesoft00 at 2007-11-28 15:00:
vkill, please correct your code. I don't know how.
I think it's still better to use reg2inf. Is there any bug in that?
|
|
2007-12-9 15:36 |
|