danBhentschel
danBhentschel

Reputation: 883

How to force a prompt for credentials when launching a program and UAC is disabled?

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

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?

Upvotes: 1

Views: 1487

Answers (1)

Syberdoor
Syberdoor

Reputation: 2619

The correct verb for this case would be

ProcessStartInfo.Verb = "runasuser"

It works well to trigger the "run as different user" authentication dialog for another process. One possible downside I found was that you will not get a proper process object returned, so you get no handle for that new process. Also it is not really possible to restart your own application with this method as the authentication dialog is running as a thread of the spawning application and only after authentication is a new process created. So if you want to "restart" your application a launcher or some other trick would probably be needed.

Upvotes: 2

Related Questions