matthewk Posted September 11, 2006 Share Posted September 11, 2006 Hello,It is kind of odd syntax to write reg add statements in a bat/cmd file. I am wondering is there a program to do take a reg file and convert it or a similar tool?? thank you Link to comment Share on other sites More sharing options...
Delprat Posted September 11, 2006 Share Posted September 11, 2006 REG IMPORT yourfile.reg will do it with no headaches...Converting a .reg to a .cmd or .bat is IMO a bad idea because .reg can be unicode, .bat and .cmd can't.++ Link to comment Share on other sites More sharing options...
matthewk Posted September 11, 2006 Author Share Posted September 11, 2006 Here is a line I have for setting the wallpaper that I use in my installs.cmd from cmdlines.txt. If I use .reg, I will not be able to use %WINDIR% I thought??REG ADD HKCR\Control Panel\Desktop /v Wallpaper /t REG_SZ /d "%WINDIR%\Web\Wallpaper\aqua1024.jpg" /fI wanted to use reg add statements to not have to hardcode c:\\windows c:\\programs etc. instead I wanted to use %windir% and %programfiles%. Does this make sense? thanks I just wonder if some tool existed to help Link to comment Share on other sites More sharing options...
DL. Posted September 11, 2006 Share Posted September 11, 2006 /t REG_SZ is not nessecary when using REG_SZ.You could use %systemroot% instead of %windir%.You cannot use a .jpg-file directly as wallpaper, it has to be a .bmp.Paths/keys with spaces need to be within quotes (" ").REG ADD "HKCR\Control Panel\Desktop" /v Wallpaper /d "%SYSTEMROOT%\Web\Wallpaper\aqua1024.bmp" /f Link to comment Share on other sites More sharing options...
Delprat Posted September 11, 2006 Share Posted September 11, 2006 (edited) I wanted to use reg add statements to not have to hardcode c:\\windows c:\\programs etc. instead I wanted to use %windir% and %programfiles%. Does this make sense? thanks I just wonder if some tool existed to helpok. here is an incomplete batch that can help you :@echo offsetlocal enableextensions enabledelayedexpansionfor /f "skip=1 tokens=*" %%a in ('type %1') do ( set line=%%a if "!line:~-1!"=="]" ( set key=!line:[=! set key=!key:]=! set key=!key:HKEY_CURRENT_CONFIG=HKCC! set key=!key:HKEY_LOCAL_MACHINE=HKLM! set key=!key:HKEY_CLASSES_ROOT=HKCR! set key=!key:HKEY_CURRENT_USER=HKCU! set key=!key:HKEY_USERS=HKU! if "!key:~0,1!"=="-" ( echo REG DELETE "!key:~1!" /f ) else ( echo REG ADD "!key!" /f )) else ( for /f "tokens=1* delims==" %%b in ('echo !line!') do ( set val=%%~b set dat=%%c if "!dat:~0,1!"=="-" ( echo REG DELETE "!key!" /v "!val!" /f ) else ( set typ=SZ if /i "!dat:~0,6!"=="dword:" set typ=DWORD&set dat=!dat:dword=!&set dat=!dat:~1! if /i "!dat:~0,7!"=="hex^(7^):"set typ=EXPAND_SZ&set dat=!dat:hex^(7^)=!&set dat=!dat:~1! echo REG ADD "!key!" /v "!val!" /t REG_!typ! /d "!dat!" /f))))name it "test.cmd" for example, and use it :C:\>test.cmd yourregfile.reg > commands.txtcommands.txt will contain the REG ADD or REG DELETE lines, you just need to copy/paste to your cmd file.don't forget to check twice the output, you will need to replace the % in expand_sz variables for example.++ Edited September 11, 2006 by Delprat Link to comment Share on other sites More sharing options...
LLXX Posted September 12, 2006 Share Posted September 12, 2006 (edited) If REG IMPORT is too easy for you, learn to use a scripting editor - they're very powerful (but difficult to learn...). Examples include sed and awk (almost a programming -I mean, scripting- language) Edited September 12, 2006 by LLXX Link to comment Share on other sites More sharing options...
Takeshi Posted September 12, 2006 Share Posted September 12, 2006 .reg can be unicode, .bat and .cmd can't.Cmd can use unicode. Link to comment Share on other sites More sharing options...
Delprat Posted September 13, 2006 Share Posted September 13, 2006 (edited) .reg can be unicode, .bat and .cmd can't.Cmd can use unicode.As you can see in my post #5 here, the batch starts with :for /f "skip=1 tokens=*" %%a in ('type %1') do (%1 is the .reg file. The TYPE command is used to convert it to ansi if it was unicode.Try to use the same unicode .reg file with and without the TYPE command, and you'll understand why i said what you quoted : if Cmd can use unicode in TYPE, that's AFAIK not the case in FOR, SET, and so on... And, if you read again you'll see i wrote ".cmd", not "Cmd" (noticed the coma this time ? )Anyway, the "hex^(7^)" should be read "hex^(2^)" (thanks Sulfurious)++ Edited September 13, 2006 by Delprat Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now