China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 06:50
Original Poster Posted 2006-11-20 07:09 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
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 ]
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
redtek +2 2006-11-20 07:12
lxmxn +3 2006-11-20 07:38
flyinspace +2 2007-04-30 05:41
Floor 2 Posted 2006-11-20 07:09 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Hope it's useful, heh heh ~ Supports *.bat

[ Last edited by vkill on 2006-11-20 at 07:10 AM ]
Floor 3 Posted 2006-11-20 13:34 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
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.
Floor 4 Posted 2006-11-21 09:08 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
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 ]
Floor 5 Posted 2006-11-21 09:37 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
I tested by exporting the reg to experiment, oh
Floor 6 Posted 2007-01-08 04:47 ·  中国 山西 阳泉 联通
初级用户
Credits 125
Posts 49
Joined 2006-12-24 08:33
19-year member
UID 74424
Gender Male
Status Offline
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.~~~~
Floor 7 Posted 2007-01-17 23:44 ·  中国 河南 南阳 联通
新手上路
Credits 18
Posts 9
Joined 2007-01-14 04:45
19-year member
UID 76457
Gender Male
Status Offline
The first time I dragged it in, it didn't work. The second time, it exited, and there were no prompts during that period.
Floor 8 Posted 2007-01-17 23:55 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
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
Floor 9 Posted 2007-01-18 08:35 ·  中国 甘肃 平凉 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
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!
Floor 10 Posted 2007-04-30 02:46 ·  中国 湖北 武汉 洪山区 电信
初级用户
Credits 68
Posts 31
Joined 2007-03-23 12:33
19-year member
UID 82670
Gender Male
Status Offline
Is this modified? It's about that variable.
Floor 11 Posted 2007-09-10 11:17 ·  中国 广东 深圳 福田区 电信
新手上路
Credits 12
Posts 6
Joined 2006-07-13 16:23
19-year member
UID 58516
Status Offline
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
Floor 12 Posted 2007-10-27 08:51 ·  中国 山东 青岛 联通
初级用户
★★
Credits 146
Posts 86
Joined 2007-10-01 11:27
18-year member
UID 98691
Gender Male
Status Offline
Post by ghost2008 on the 11th floor: Very useful
Floor 13 Posted 2007-10-27 12:56 ·  中国 上海 杨浦区 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
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.
Floor 14 Posted 2007-11-28 15:00 ·  中国 河北 邯郸 电信
新手上路
Credits 4
Posts 2
Joined 2006-09-25 07:02
19-year member
UID 63593
Status Offline
vkill, please correct your code for me. I don't know how.
Floor 15 Posted 2007-12-09 15:36 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
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?
Forum Jump: