Page 1 of 1

Split/insert comma to string?

Posted: 22 May 2011 11:43
by mads
Hi

I'm trying to export two REG_Binary value from the users profile to a .reg file (This script should run as an logoff script)

But right now I'm not able to get the format correct, because the string I get from my script does not contain the commas (,) for every two digit.

The string is: 540065007300740020007300690067000000
But it has to be: 54,00,65,00,73,00,74,00,20,00,73,00,69,00,67,00,00,00,

So how do I insert these commas to the string?

Here is my script (I only have made it for one value so fare):

Code: Select all

@echo off
setlocal
set rkey=HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Default Outlook Profile\9375CFF0413111d3B88A00104B2A6676\00000001
set rvalue="Reply-Forward Signature"
set regexe=%SystemRoot%\System32\Reg.exe
for /f "Tokens=4" %%a in ('%regexe% QUERY "%rkey%" /v %rvalue%') do (
set rdata=%%a
)

set regfile=%userprofile%\mytst.reg

echo Windows Registry Editor Version 5.00>%regfile%
echo.>>%regfile%
echo [%rkey%]>>%regfile%
echo %rvalue%^=hex:%rdata%>>%regfile%
echo.>>%regfile%

endlocal


Hope someone can help me, I'm really stuck right now :(

Thanks

Re: Split/insert comma to string?

Posted: 22 May 2011 12:21
by aGerman
Hmm, why don't you use REG EXPORT ?

How ever. Have a look at this example:

Code: Select all

@echo off &setlocal
set "string=540065007300740020007300690067000000"

setlocal enabledelayedexpansion
set /a n=0
:_Loop
set "hex=!string:~%n%,2!"
set "newString=%newString%,%hex%"
set /a n+=2
if defined hex goto :_Loop
endlocal &set "newstring=%newString:~1,-1%"

echo %newString%

pause


Regards
aGerman

Re: Split/insert comma to string?

Posted: 22 May 2011 12:25
by mads
Hi aGerman

Thanks, I will take a look and see if I can get it to work.

I'm not using REG EXPORT, because it can only tak a whole key and not a single value, unless you know a trick?

Thanks again.

/Mads

Re: Split/insert comma to string?

Posted: 22 May 2011 12:39
by aGerman
No there is no trick.
But you can use REG ADD with your origin string.

Regards
aGerman

Re: Split/insert comma to string?

Posted: 22 May 2011 13:09
by mads
Ok, the thing is that the string is not the same for every user, because they have different signatures and I need to export it not add it.

But I think I got your code to work THANK YOU so much, this help me a lot and.