Search code examples
c#.netuacwindows-server-2012elevation

How would my C# code running under "SYSTEM" account start a program which requires elevation without triggering a prompt?


My C# code is running on a faraway Windows Server where I cannot login, only deploy code. I want to run Process Monitor from that code - start it in "quiet" mode, then stop it after a while. The code which would run Process Monitor is running under "NT AUTHORITY\SYSTEM" local account so I assume it has all the rights required.

However if I run Process Monitor on my developer box it triggers a rights elevation prompt. If I run it from command line locally:

procmon /Terminate

then I see an elevation prompt, confirm elevation and the process exits (as expected).

If I run it from inside C# code on the faraway server:

using (var process = new System.Diagnostics.Process())
{
    process.StartInfo.FileName = pathToProcMonExe;
    process.StartInfo.Arguments = "/Terminate";
    process.Start();
    process.WaitForExit();
    WriteToLog("Exited");
}

then it looks like it just hangs on the elevation prompt and the process never exits.

Again I cannot login there and confirm elevation. I need to do everything programmatically.

My process runs under "NT AUTHORITY\SYSTEM". How does it run Process Monitor which requires elevation without triggering the prompt?


Solution

  • Turns out it was not an elevation prompt. It was a "here's my license agreement, please read and accept it" dialog box shown by Process Monitor despite the silent mode. Once license agreement is accepted Process Monitor can run just fine without elevation prompts in that environment.