settings using registry

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

settings using registry

#1 Post by Adrianvdh » 07 Jun 2013 15:23

Hello everyone
I have made a similar post to this topic but I did not understand it. I am writing a really big program and it uses settings. So it saves a variable "set var=0" into a bat file and the program would call that bat file and there you go. Bur now I would like to have a more secure way of saving variables... Could some one please give me a quick tutorial on how to...

write a variable to a reg key
read a reg key and store it in a variable
delete a reg key...

For example I would like to save the text "disabled" into a key for a mode in my program and my program could read that key and store it in a variable...

Thank you for all your time :)

Acy Forsythe
Posts: 126
Joined: 10 Jun 2011 10:30

Re: settings using registry

#2 Post by Acy Forsythe » 07 Jun 2013 16:08

I'm not sure you are in the correct forum considering you mentioned that you are writing a "really big program"

But just in case you are actually writing a batch script, I'll point you in the right direction...

Reg.exe is the commandline registry editor so you'll use it to import/export keys into *.reg files.

These files are standard text files and can be written by batch files and parsed by batch files to read/write the registry keys you are wanting to use.

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: settings using registry

#3 Post by Adrianvdh » 07 Jun 2013 16:27

So could you give me a tutorial , yes it is a bat file (200KB in size)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: settings using registry

#4 Post by foxidrive » 08 Jun 2013 03:16

Adrianvdh wrote:So could you give me a tutorial


Instead, how about you read the help for reg.exe and ask for help on any specific issue that arises.

alid0381
Posts: 28
Joined: 09 May 2012 10:37

Re: settings using registry

#5 Post by alid0381 » 08 Jun 2013 11:58

For using registry :

This page may be for you. :)

http://technet.microsoft.com/fr-fr/libr ... 10%29.aspx

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: settings using registry

#6 Post by foxidrive » 08 Jun 2013 21:18

hehe Is the OP a French native?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: settings using registry

#7 Post by aGerman » 09 Jun 2013 06:29

OK, here's an example of how to work with the registry. First of all before experimenting make sure you backup the registry key (for my example HKEY_CURRENT_USER\Software) into a .reg file. Otherwise accidentally deleted keys are gone. Also make sure you understand what you're doing!

Code: Select all

@echo off &setlocal

:: good place for your data
set "RegKey=HKCU\Software\MyBatProg"

:: add new data
>nul reg add "%RegKey%" /v "Value1" /t REG_SZ /d "Hello World!" /f
>nul reg add "%RegKey%" /v "Value2" /t REG_SZ /d "123" /f

:: read data and assign a variable
for /f "tokens=2*" %%i in ('reg query "%RegKey%" /v "Value1"') do set "txt=%%j"
echo Text: %txt%
for /f "tokens=2*" %%i in ('reg query "%RegKey%" /v "Value2"') do set "num=%%j"
echo Number: %num%

:: change existing data (same as adding new)
>nul reg add "%RegKey%" /v "Value2" /t REG_SZ /d "1000" /f
:: check
for /f "tokens=2*" %%i in ('reg query "%RegKey%" /v "Value2"') do set "num=%%j"
echo Number: %num%

pause

:: delete a certain value
>nul reg delete "%RegKey%" /v "Value2" /f
:: check (error if the deletion was successful)
reg query "%RegKey%" /v "Value2"

:: delete the entire key
>nul reg delete "%RegKey%" /f
:: check (error if the deletion was successful)
reg query "%RegKey%"

pause

Regards
aGerman

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: settings using registry

#8 Post by Adrianvdh » 02 Jul 2013 06:25

So a "Key" would be like a folder and a "Value" would be like a file?

Post Reply