Jump to content

.reg to bat/cmd


matthewk

Recommended Posts


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" /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

Link to comment
Share on other sites

/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

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

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.

++

Edited by Delprat
Link to comment
Share on other sites

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 by LLXX
Link to comment
Share on other sites

:lol:

.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... :wacko:

And, if you read again you'll see i wrote ".cmd", not "Cmd" (noticed the coma this time ? :rolleyes: )

Anyway, the "hex^(7^)" should be read "hex^(2^)" (thanks Sulfurious)

++

Edited by Delprat
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...