Skip navigation

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


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 off
setlocal DISABLEDELAYEDEXPANSION
if \{%1\}==\{\} goto syntax
set RegFile=%1
set regout=%~DPN1.txt
set regout="%regout:"=%" 
if not exist %RegFile% goto syntax
if exist %regout% del /q %regout% 
@echo %regout%
set tblend=¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿
set table=¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿ !"#$%%§'()*+,-./0123456789:;L=G?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\]ˆ_`abcdefghijklmnopqrstuvwxyz\{i\}~%tblend%%tblend%
set next=N
set RegType=
for /f "Tokens=*" %%a in ('Type %RegFile%') do set line=%%a&call :parse
endlocal
goto :EOF
:parse
if defined RegType goto parse2
@echo Begin
if /i "%line:~0,8%" EQU "REGEDIT4" set RegType=4&goto parse1
if /i "%line:~0,33%" EQU "Windows Registry Editor Version 5" set RegType=5&goto parse1
@echo %RegFile% is NOT a .REG file.
goto syntax
:outl
if "%line:~0,1%" EQU "" goto outl1 
if "%line:~0,2%" EQU "  " goto outl1 
@echo %line% >>%regout%
goto :EOF
:outl1
@echo. >>%regout%
goto :EOF
:outk
if "%keep:~0,1%" EQU "" goto outk1 
if "%keep:~0,1%" EQU "  " goto outk1 
@echo %keep% >>%regout%
goto :EOF
:outk1
if "%type%" EQU "M" goto :EOF
@echo. >>%regout%
goto :EOF
:parse1
call :outl
goto :EOF
:parse2
if "%next%" EQU "Y" goto next1
if \{^%line:~0,1%\} EQU \{\[\} goto parse4  
set line=%line:&=§%
set line=%line:\"=¿¿¿%
set line=%line:"=%
set /a cnt=0
:fnd
set /a cnt=%cnt% + 1
if %cnt% GTR 79 goto :parse2A
call set char=^%%line:~%cnt%,1%%
if not "%char%" EQU "=" goto fnd
call set char=^%%line:~%cnt%,7%%
if /i "%char%" EQU "=dword:" goto dword
call set char=^%%line:~%cnt%,8%%
if /i "%char%" EQU "=hex(2):" goto regxsz
if /i "%char%" EQU "=hex(7):" goto regmsz
:parse2A
set next=N
:parse3
set line=%line:¿¿¿='%
call :outl
goto :EOF
:parse4
@echo.>>%regout%
call :outl
goto :EOF
:dword
call :outl
goto :EOF
:regxsz
set type=X
set /a pos=%cnt% + 8
call set begin=%%line:~0^,%pos%%%
call set remain=%%line:~%pos%,80%%
call set keep=%%line:~0,^%cnt%%%=EXPAND=
if "%remain%" EQU "" goto outk
if "%remain%" LSS "0" goto outk
set line= 
set /a outcnt=0
call :hex
goto :EOF
:regmsz
set type=M
set /a pos=%cnt% + 8
call set begin=%%line:~0^,%pos%%%
call set remain=%%line:~%pos%,80%%
call set keep=%%line:~0,^%cnt%%%=MULTI=
if "%remain%" EQU "" goto outk
if "%remain%" LSS "0" goto outk
set line= 
set /a outcnt=0
call :hex
goto :EOF
:hex
set /a cnt=0
:hex1
call set char1=%%remain:~%cnt%,1%%
set /a cnt=%cnt% + 1
call set char2=%%remain:~%cnt%,1%%
if "%char1%" EQU "0" goto hex4
:hex1A
if "%char1%" EQU "" goto hex3
if "%char1%" EQU "\" goto hex2
if /i "%char1%" GTR "f" set char1=f
if /i "%char2%" GTR "f" set char2=f
set /a char1=0x%char1%
set /a char2=0x%char2%
set /a pos=%char1% * 16
set /a pos=%pos% + %char2%
if %pos% GTR 255 goto hex1AB
call set char=^%%table:~%pos%,1%%
if \{^%char%\} EQU \{¿\} goto hex1AB
set keep=%keep%^%char%
set /a outcnt=%outcnt% + 1
set /a cnt=%cnt% + 2
goto hex1
:hex1AB
set keep=%keep%¿%char1%%char2%
set /a cnt=%cnt% + 2
set /a outcnt=%outcnt% + 3
goto hex1
:hex2
set next=Y
if %outcnt% GTR 160 goto hex3
goto :EOF
:hex3
set next=N
call :outk
goto :EOF
:hex4
if not "%char2%" EQU "0" goto hex1A
if "%type%" EQU "X" set /a cnt=%cnt% + 2&goto hex1
:hex5
set /a cnt=%cnt% + 2
call set char1=%%remain:~%cnt%,1%%
set /a cnt=%cnt% + 1
call set char2=%%remain:~%cnt%,1%%
if not "%char1%" EQU "0" goto hex1B
if not "%char2%" EQU "0" goto hex1B
call :outk
set keep= 
set /a cnt=%cnt% + 2
goto hex1
:hex1B
if "%RegType%" EQU "5" goto hex1C
call :outk
set keep= 
:hex1C
if "%char1%" EQU "\" goto hex2
if "%char1%" EQU "" goto hex3
goto hex1A
:next1
set next=N
set remain=%line%
call :hex
goto :EOF
:syntax
@echo Syntax: ViewReg RegFile
endlocal
goto :EOF
:logic
@echo logic:%line%>>%regout%
endlocal



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish