Background
My application (.NET, C#) performs an in-app upgrade. Depending on installation configuration, the upgrade may need to launch a separate process that requires Administrator privileges. The launched program's manifest specifies that it requires Administrator privileges.
This normally works fine, but if UAC is disabled, and the user is not an admin, then it fails miserably. See below.
Scenarios
- UAC is enabled, and the user is an admin - Windows prompts for elevation, and the program executes successfully.
- UAC is enabled, and the user is not an admin - Windows prompts for credentials, and the program executes successfully.
- UAC is disabled, and the user is an admin - No prompts, the program executes successfully.
- UAC is disabled, and the user is not an admin - No prompts, the program starts but fails miserably.
This fourth scenario is the one that I want to solve. I have a rather large customer company that has a policy of turning off UAC on all corporate PCs, for whatever reason.
Mitigation
The simplest solution is to detect this fourth scenario and give the user guidance. I have no problem detecting when this fourth scenario is in effect, and I can then open up an Explorer window to a directory containing the program to execute, and a text file that walks the user through the process of Shift-Right-Click -> "Run as different user".
Desired solution
If I detect that I am in this fourth scenario, then I perform some coding magic to automatically start the process from my application AS IF the user had manually opted to "Run as different user".
I don't know how to implement this solution. I tried to set ProcessStartInfo.Verb = "runas"
, as I have seen suggested, but that doesn't seem to do anything useful in the absence of UAC. Any ideas?
Process.GetProcessByName()
to detect when the process exits, and then use artifacts to determine success or failure. Sound reasonable? – danBhentschel