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
[ Last edited by vkill on 2006-11-21 at 09:31 AM ]
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 ]
Recent Ratings for This Post
( 3 in total)
Click for details
| Rater | Score | Time |
|---|---|---|
| redtek | +2 | 2006-11-20 07:12 |
| lxmxn | +3 | 2006-11-20 07:38 |
| flyinspace | +2 | 2007-04-30 05:41 |

