convert reg:multiline_hex to string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Hans_FHL
Posts: 1
Joined: 04 Feb 2016 12:35

convert reg:multiline_hex to string

#1 Post by Hans_FHL » 04 Feb 2016 12:50

Hallo,


Howto convert multiline_hex to string?
(which read from registry before)

Example:

-Source:
DhcpDefaultGateway"=hex(7):31,00,39,00,32,00,2e,00,31,00,36,00,38,00,2e,00,37,\
00,33,00,2e,00,33,00,33,00,00,00,00,00

-Result (expected):
IP=192.168.73.33


link to thread are welcome.

regards Hans

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: convert reg:multiline_hex to string

#2 Post by Squashman » 04 Feb 2016 15:03

If you search the forums you will probably find your answer on converting hex to ascii. It has been discussed at great length. But for numbers you don't even need a brain. It is always the second number of the hex code.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: convert reg:multiline_hex to string

#3 Post by aGerman » 05 Feb 2016 14:21

Hans
that code might work for you:

Code: Select all

@echo off &setlocal
set "infile=test.reg"

setlocal EnableDelayedExpansion
set "continue="
for /f %%i in ('type "!infile!"') do (
  set "ln=%%i"
  if !ln:~0^,20!=="DhcpDefaultGateway" (
    set "hex=!ln:*:=!"
  ) else if defined continue (
    set "hex=!hex!!ln!"
  )
  if "!hex:~-1!"=="\" (
    set "hex=!hex:~,-1!"
    set "continue=1"
  ) else set "continue="
)
set "gateway="
for %%i in (!hex!) do (
  if "%%i" neq "00" (
    set /a n=0x%%i
    cmd /c exit !n!
    set "gateway=!gateway!!=ExitCodeAscii!"
  )
)
endlocal &set "gateway=%gateway%"

echo %gateway%
pause

Regards
aGerman

Post Reply