Page 1 of 1

settings using registry

Posted: 07 Jun 2013 15:23
by Adrianvdh
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 :)

Re: settings using registry

Posted: 07 Jun 2013 16:08
by Acy Forsythe
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.

Re: settings using registry

Posted: 07 Jun 2013 16:27
by Adrianvdh
So could you give me a tutorial , yes it is a bat file (200KB in size)

Re: settings using registry

Posted: 08 Jun 2013 03:16
by foxidrive
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.

Re: settings using registry

Posted: 08 Jun 2013 11:58
by alid0381
For using registry :

This page may be for you. :)

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

Re: settings using registry

Posted: 08 Jun 2013 21:18
by foxidrive
hehe Is the OP a French native?

Re: settings using registry

Posted: 09 Jun 2013 06:29
by aGerman
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

Re: settings using registry

Posted: 02 Jul 2013 06:25
by Adrianvdh
So a "Key" would be like a folder and a "Value" would be like a file?