Reputation: 32854
Is there a way to mark a .EXE to request it be run as admin? So that:
I know how to do this with 2 .exe programs. But I'd like to do it with one. This program enters the user's license key. In HKLM if the app has admin rights (so all users have the key). In HKCU if no admin rights.
Upvotes: 2
Views: 2613
Reputation: 18944
You can get 1 and 2 by requesting highestAvailable
instead of requireAdmin
. I don't like it, though, because throughout the rest of the app you may need to test to see if you're elevated or not.
You can't get #4. If an app tries to launch, shows a UAC dialog, and the user rejects the UAC, the app does not launch. If you have just part of your application that needs elevation, you are best to move that part to a separate exe and put a manifest on that exe that requires elevation, then leave the main app not requiring it.
Upvotes: 1
Reputation: 36308
There is no way to mark an executable so that it will continue to run without admin privilege if the user rejects the elevation prompt. However, a process can attempt to launch a second copy of itself from the same executable with elevated privileges, and either pass the work to the new process (if it launches successfully) or continue the work itself (if not).
See this answer for an example of how to elevate yourself.
Upvotes: 3