Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Import reg file to the registry without user confirmation box

Tags:

c#

registry

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(); 
like image 982
User6996 Avatar asked Sep 02 '25 01:09

User6996


2 Answers

Send the file as a parameter to regedit.exe:

Process regeditProcess = Process.Start("regedit.exe", "/s key.reg");
regeditProcess.WaitForExit();
like image 98
Kobi Avatar answered Sep 05 '25 18:09

Kobi


The code in answer 2 is correct, but not complete. It will work when the directory where you are refering to has no spacings in the path/file you are refering to example C:\ProgramFiles\key.reg will work fine, but C:\Program Files\key.reg WON'T WORK because there are spaces in the path.

The solution:

string directory= @"C:\Program Files (x86)\key.reg";
Process regeditProcess = Process.Start("regedit.exe", "/s \"" + directory + "\"");
regeditProcess.WaitForExit();
like image 42
ses Avatar answered Sep 05 '25 18:09

ses