Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically change a value in the Window's Registry?

I need to programmatically change the "Level" String found in \HKEY_CURRENT_USER\Software\Intuit\QBWebConnector to "Verbose"

What is the best way to do this? C#, bat file? I have never tinkered with the registry before...

Thanks.

like image 408
mmattax Avatar asked Mar 13 '09 18:03

mmattax


2 Answers

If the registry entry you are going to change is already in the registry, the simplest way to create a *.reg file that changes the registry entry as you need it is as follows:

  1. Open Regedit
  2. Locate the registry folder right above the registry key you are going to change in the treeview on the left.
  3. Right-click the folder and select "Export".
  4. Open the file you just exported with notepad and delete anything apart from the first line ("Windows Registry Editor Version 5.00" or similar), the folder name ( [HKEY_CURRENT_USER\Software\Intuit\QBWebConnector] in your case) and the name value pair for the key you would like to change
  5. Edit the value you would like to change appropriately and save the file. In your case you should end up with the following *.reg file:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Intuit\QBWebConnector]

"Level"="Verbose"

Double-clicking the file and confirming the security warning(s) will perform the changes on your registry.

Or, in a batchfile, you can silently import the registry file via "REGEDIT /S pathname"

Be careful with the registry since you might otherwise wreck your windows installation.

like image 109
Adrian Grigore Avatar answered Oct 13 '22 09:10

Adrian Grigore


Here are some more ways in order of easyness not mentioned above:

  1. Reg.exe add - Type reg /? to see options and the Reg reference for details.
  2. Regini.exe [scriptfile] - More powerful than .reg files, you can delete subkeys and data items and set permissions. Type regini /? to see instructions or the MSDN article Distributing Registry Changes for details.
  3. ATL::CRegKey class, SetStringValue() member, see MSDN.
  4. .NET Registry Class SetValue() (C#, C++, F#, VB) - See MSDN reference.
  5. Win32 APIs such as RegSetKeyValue(). See the Registry Functions reference.
like image 37
User5910 Avatar answered Oct 13 '22 11:10

User5910