I need to restart IIS from a C#/.NET application. This seems like a trivial issue, but I haven't had success thus far, and none of the answers from this question have worked.
I am a local administrator on the machine.
I've tried this:
var process = new Process
{
StartInfo =
{
Verb = "runas",
WorkingDirectory = @"C:\Windows\System32\",
FileName = @"issreset.exe"
}
};
process.Start();
but this throws a Win32Exception - cannot find the file specified. I've also tried various combinations of putting the whole path in FileName, and using UseShellExecute but neither of those options helped.
I've also tried invoking it via the command line:
var process = new Process
{
StartInfo =
{
Verb = "runas",
WindowStyle = ProcessWindowStyle.Hidden,
FileName = @"cmd.exe",
Arguments = "/C iisreset"
}
};
process.Start();
and this works, but it gives a UAC prompt, which I cannot have as this application will be running without user intervention.
Is there anything else I could try?