Reputation: 27660
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.
Upvotes: 11
Views: 9578
Reputation: 110
If you want to edit programmatically registry file, the best way (in my opinion) is the C#! you can use these codes to add, edit or delete registry keys:
Add or Edit:
Registry.SetValue("HKEY_LOCAL_MACHINE\\" + keyPath , "KeyName", "KeyValue", RegistryValueKind.String);
Delete:
using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
using (var myKey = hklm.OpenSubKey(keyPath, true))
{
if (myKey == null)
MessageBox.Show("Register alredy deleted");
else
{
myKey.DeleteValue("KeyName");
myKey.Close();
MessageBox.Show("Register deleted!");
}
}
Important point:
your app must be run as an administrator! for this, you can add a manifest to your app.
This is a simple sample to edit registery file:
https://github.com/hgh6484/AddKeyToRegistry
Upvotes: 0
Reputation: 485
Here are some more ways in order of easyness not mentioned above:
reg /?
to see options and the Reg reference for details.regini /?
to see instructions or the MSDN article Distributing Registry Changes for details.Upvotes: 6
Reputation: 33318
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:
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.
Upvotes: 7
Reputation: 60922
Actually, the easiest way to change a bunch of registry keys is to use a *.reg file and simply load it into the registry. But be careful: You generally can't send these files to people via e-mail, because they get filtered by many mail servers.
We occasionally use this technique to pass around application configurations and test them on other machines.
I only mention this non-programmatic solution because you suggested that either a C# application or a batch file would be OK, which suggests that you're looking for something lightweight and you aren't too worried about the details.
Upvotes: 2