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
.reg to bat/cmd Program Request
#1
Posted 10 September 2006 - 09:54 PM
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
#2
Posted 11 September 2006 - 06:38 AM
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.
++
#3
Posted 11 September 2006 - 08:11 AM
REG ADD HKCR\Control Panel\Desktop /v Wallpaper /t REG_SZ /d "%WINDIR%\Web\Wallpaper\aqua1024.jpg" /f
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 help
#4
Posted 11 September 2006 - 08:58 AM
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
#5
Posted 11 September 2006 - 11:21 AM
matthewk, on Sep 11 2006, 04:11 PM, said:
ok. here is an incomplete batch that can help you :
@echo off
setlocal enableextensions enabledelayedexpansion
for /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.txt
commands.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.
++
This post has been edited by Delprat: 11 September 2006 - 11:24 AM
#6
Posted 11 September 2006 - 09:31 PM
This post has been edited by LLXX: 11 September 2006 - 09:32 PM
#7
Posted 12 September 2006 - 03:21 PM
#8
Posted 13 September 2006 - 06:29 AM
Takeshi, on Sep 12 2006, 11:21 PM, said:
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)
++
This post has been edited by Delprat: 13 September 2006 - 06:32 AM



Help

Back to top









