Reputation: 1428
I have created a registry file in C# to configure a client email account. I then crated a process then started to execute the reg file, like so:
var proc = new Process();
var pi = new ProcessStartInfo();
pi.UseShellExecute = true;
pi.FileName = strRegPath;
proc.StartInfo = pi;
proc.Start();
This works fine, but however it requires the use to interact with the importing of the regustry file by clicking yes. Is there anyway I can run this in the background without interacting with the user?
Upvotes: 1
Views: 5084
Reputation: 1683
REGEDIT.EXE
has a /s
option which suppresses the dialog box.
So, you would change the pi.FileName
to regedit.exe
and add arguments:
pi.Arguments = "/s " + strRegPath;
and you don't need pi.UseShellExecute
now because you aren't using the shell tables that link file extensions to an executable to open them.
In fact, you don't even need ProcessStartInfo
, you could just do this
System.Diagnostics.Process.Start("regedit.exe", "/s \""+strRegPath+"\"");
However, unless you are using some sort of 3rd party reg file, you would be much better changing the registry entries using the Microsoft.Win32.Registry
class.
UAC pops up when you start regedit because it can alter values in HKEY_LOCAL_MACHINE
which requires elevation. However, I would have thought all of the client email account settings are under HKEY_CURRENT_USER
. Subkeys below HKEY_CURRENT_USER
can be accessed using the Registry class without requiring elevation, and so would not create any UAC pop-up windows, also allowing the script to be used by logins that are not administrators. This is probably the much superior route than trying to use .reg files.
Upvotes: 3