MSFN Forum: .reg to bat/cmd - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

.reg to bat/cmd Program Request Rate Topic: -----

#1 User is offline   matthewk 

  • Member
  • PipPip
  • Group: Members
  • Posts: 288
  • Joined: 07-June 05

  Posted 10 September 2006 - 09:54 PM

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 :)


#2 User is offline   Delprat 

  • Poll: Why are you reading this ?
  • PipPipPip
  • Group: Members
  • Posts: 481
  • Joined: 18-May 05

Posted 11 September 2006 - 06:38 AM

:lol:

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 User is offline   matthewk 

  • Member
  • PipPip
  • Group: Members
  • Posts: 288
  • Joined: 07-June 05

Posted 11 September 2006 - 08:11 AM

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

#4 User is offline   DL. 

  • Tweaker or whatever I happen to be focused on at the moment..
  • PipPipPip
  • Group: Members
  • Posts: 489
  • Joined: 05-March 05
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 11 September 2006 - 08:58 AM

/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


#5 User is offline   Delprat 

  • Poll: Why are you reading this ?
  • PipPipPip
  • Group: Members
  • Posts: 481
  • Joined: 18-May 05

Posted 11 September 2006 - 11:21 AM

View Postmatthewk, on Sep 11 2006, 04:11 PM, said:

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.

++

This post has been edited by Delprat: 11 September 2006 - 11:24 AM


#6 User is offline   LLXX 

  • MSFN Junkie
  • PipPipPipPipPipPipPipPipPip
  • Group: Banned
  • Posts: 3,399
  • Joined: 04-December 05

Posted 11 September 2006 - 09:31 PM

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)

This post has been edited by LLXX: 11 September 2006 - 09:32 PM


#7 User is offline   Takeshi 

  • Legitchecking...
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,107
  • Joined: 09-September 04

Posted 12 September 2006 - 03:21 PM

View PostDelprat, on Sep 11 2006, 07:38 AM, said:

:lol:

.reg can be unicode, .bat and .cmd can't.


Cmd can use unicode.

#8 User is offline   Delprat 

  • Poll: Why are you reading this ?
  • PipPipPip
  • Group: Members
  • Posts: 481
  • Joined: 18-May 05

Posted 13 September 2006 - 06:29 AM

View PostTakeshi, on Sep 12 2006, 11:21 PM, said:

View PostDelprat, on Sep 11 2006, 07:38 AM, said:

: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)

++

This post has been edited by Delprat: 13 September 2006 - 06:32 AM


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy