C# winforms - How can I import a reg
file into the registry? The following code is displaying a confirmation box to the user (yes/no).
Process regeditProcess = Process.Start("key.reg", "/S /q"); // not working
regeditProcess.WaitForExit();
C# winforms - How can I import a reg
file into the registry? The following code is displaying a confirmation box to the user (yes/no).
Process regeditProcess = Process.Start("key.reg", "/S /q"); // not working
regeditProcess.WaitForExit();
Send the file as a parameter to regedit.exe
:
Process regeditProcess = Process.Start("regedit.exe", "/s key.reg");
regeditProcess.WaitForExit();
Instead of executing a .reg
file, you should be able to make your changes to the registry using the functionality provided in the Microsoft.Win32
namespace.
It is quite easy to create a registry key using this API:
RegistryKey key = Registry.CurrentUser.CreateSubKey("Names");
key.SetValue("Name", "Isabella");
key.Close();
Unless you need to create a bulk load of new keys, I believe the API is a more scalable and maintable approach. If at some point, you need decide to make it optional to write your settings in the system-wide or the per-user branch of the registry, most of your code will be reusable for both cases. Simply pick another key to do the changes upon.
Maybe more important, the API lets you specify exactly (in code) how to handle cases where the key(s) you are inserting already exists in the registry. Should i delete the existing keys and insert mine, updates values within the existing keys, silently ignore or raise an exception?