internal static int? RunElevated(string fileName, string arguments, bool elevate, bool waitForExit)
{
var processInfo = new ProcessStartInfo
{
FileName = fileName,
Arguments = arguments
};
if (elevate)
{
processInfo.Verb = "runas";
}
try
{
var process = Process.Start(processInfo);
if (waitForExit && process != null)
{
process.WaitForExit();
return process.ExitCode;
}
return 0;
}
catch (Win32Exception)
{
// Do nothing. Probably the user canceled the UAC window
return null;
}
}