|
原帖由 Civiwu 于 2007-1-18 12:32 PM 发表
直接将注册表文件转换成批处理命令,哪位大侠有上传一个吧!
来自vkill' Blog:http://blog.yx127.com/?action=show&id=192
sed下载:http://www.yx127.com/tools/sed_4.0.7x.rar
原下载地址有问题,故直接从vkill'tool中引过来
- REG2BAT.bat
- @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/[/#/" |more>%temp%1
- cls
- ::显示错误并自动除错
- cd.>%temp%2
- sed "/^#HKEY_.*\.*]/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/^[ \t]*//;s/[ \t]*$//" |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
复制代码 |
|