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

前端 未结 4 555
情深已故
情深已故 2020-12-23 17:49

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).

         


        
4条回答
  •  失恋的感觉
    2020-12-23 18:40

    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();
    

提交回复
热议问题