JSI Tip 6410. View REG_EXPAND_SZ and REG_MULTI_SZ data type in a .REG file in plain text.

Jerold Schulman

March 5, 2003

3 Min Read
ITPro Today logo in a gray background | ITPro Today


When you open a .REG file, the content of REG_EXPAND_SZ and REG_MULTI_SZ data types are presented as hexadecimal strings, using hex(2): and hex(7): respectively.

I have scripted ViewReg.bat to convert these back to plain text, to avoid having to view the strings in the Registry Editor. The syntax for using ViewReg.bat is:

ViewReg.bat FileName.reg

The output file will be in the same folder as FileName.reg and will be named FileName.txt. If the string of a REG_EXPAND_SZ or REG_MULTI_SZ data type contains an unprintable character, ¿ followed by the hexadecimal code will be displayed.

NOTE: Since ViewReg.bat parses each character in the FileName.reg file, it runs a long time and consumes significant CPU cycles. You might want to use start /low ViewReg.bat FileName.reg to start it.

NOTE: The FOR command in CMD.EXE does NOT like to process large files. You should restrict the file size to under 1 MB. If you cut unwanted lines from the FileName.reg file, the first line must be included, so ViewReg.bat can determine whether the file uses REGEDIT4 or Windows Registry Editor Version 5.nn format.

NOTE: See How can a batch file generate a .REG file that contains a REG_EXPAND_SZ data type with variable data?

ViewReg.bat contains:

@echo offsetlocal DISABLEDELAYEDEXPANSIONif {%1}=={} goto syntaxset RegFile=%1set regout=%~DPN1.txtset regout="%regout:"=%" if not exist %RegFile% goto syntaxif exist %regout% del /q %regout% @echo %regout%set tblend=¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿set table=¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿ !"#$%%§'()*+,-./0123456789:;L=G?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]ˆ_`abcdefghijklmnopqrstuvwxyz{i}~%tblend%%tblend%set next=Nset RegType=for /f "Tokens=*" %%a in ('Type %RegFile%') do set line=%%a&call :parseendlocalgoto :EOF:parseif defined RegType goto parse2@echo Beginif /i "%line:~0,8%" EQU "REGEDIT4" set RegType=4&goto parse1if /i "%line:~0,33%" EQU "Windows Registry Editor Version 5" set RegType=5&goto parse1@echo %RegFile% is NOT a .REG file.goto syntax:outlif "%line:~0,1%" EQU "" goto outl1 if "%line:~0,2%" EQU "  " goto outl1 @echo %line% >>%regout%goto :EOF:outl1@echo. >>%regout%goto :EOF:outkif "%keep:~0,1%" EQU "" goto outk1 if "%keep:~0,1%" EQU "  " goto outk1 @echo %keep% >>%regout%goto :EOF:outk1if "%type%" EQU "M" goto :EOF@echo. >>%regout%goto :EOF:parse1call :outlgoto :EOF:parse2if "%next%" EQU "Y" goto next1if {^%line:~0,1%} EQU {[} goto parse4  set line=%line:&=§%set line=%line:"=¿¿¿%set line=%line:"=%set /a cnt=0:fndset /a cnt=%cnt% + 1if %cnt% GTR 79 goto :parse2Acall set char=^%%line:~%cnt%,1%%if not "%char%" EQU "=" goto fndcall set char=^%%line:~%cnt%,7%%if /i "%char%" EQU "=dword:" goto dwordcall set char=^%%line:~%cnt%,8%%if /i "%char%" EQU "=hex(2):" goto regxszif /i "%char%" EQU "=hex(7):" goto regmsz:parse2Aset next=N:parse3set line=%line:¿¿¿='%call :outlgoto :EOF:parse4@echo.>>%regout%call :outlgoto :EOF:dwordcall :outlgoto :EOF:regxszset type=Xset /a pos=%cnt% + 8call set begin=%%line:~0^,%pos%%%call set remain=%%line:~%pos%,80%%call set keep=%%line:~0,^%cnt%%%=EXPAND=if "%remain%" EQU "" goto outkif "%remain%" LSS "0" goto outkset line= set /a outcnt=0call :hexgoto :EOF:regmszset type=Mset /a pos=%cnt% + 8call set begin=%%line:~0^,%pos%%%call set remain=%%line:~%pos%,80%%call set keep=%%line:~0,^%cnt%%%=MULTI=if "%remain%" EQU "" goto outkif "%remain%" LSS "0" goto outkset line= set /a outcnt=0call :hexgoto :EOF:hexset /a cnt=0:hex1call set char1=%%remain:~%cnt%,1%%set /a cnt=%cnt% + 1call set char2=%%remain:~%cnt%,1%%if "%char1%" EQU "0" goto hex4:hex1Aif "%char1%" EQU "" goto hex3if "%char1%" EQU "" goto hex2if /i "%char1%" GTR "f" set char1=fif /i "%char2%" GTR "f" set char2=fset /a char1=0x%char1%set /a char2=0x%char2%set /a pos=%char1% * 16set /a pos=%pos% + %char2%if %pos% GTR 255 goto hex1ABcall set char=^%%table:~%pos%,1%%if {^%char%} EQU {¿} goto hex1ABset keep=%keep%^%char%set /a outcnt=%outcnt% + 1set /a cnt=%cnt% + 2goto hex1:hex1ABset keep=%keep%¿%char1%%char2%set /a cnt=%cnt% + 2set /a outcnt=%outcnt% + 3goto hex1:hex2set next=Yif %outcnt% GTR 160 goto hex3goto :EOF:hex3set next=Ncall :outkgoto :EOF:hex4if not "%char2%" EQU "0" goto hex1Aif "%type%" EQU "X" set /a cnt=%cnt% + 2&goto hex1:hex5set /a cnt=%cnt% + 2call set char1=%%remain:~%cnt%,1%%set /a cnt=%cnt% + 1call set char2=%%remain:~%cnt%,1%%if not "%char1%" EQU "0" goto hex1Bif not "%char2%" EQU "0" goto hex1Bcall :outkset keep= set /a cnt=%cnt% + 2goto hex1:hex1Bif "%RegType%" EQU "5" goto hex1Ccall :outkset keep= :hex1Cif "%char1%" EQU "" goto hex2if "%char1%" EQU "" goto hex3goto hex1A:next1set next=Nset remain=%line%call :hexgoto :EOF:syntax@echo Syntax: ViewReg RegFileendlocalgoto :EOF:logic@echo logic:%line%>>%regout%endlocal



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like