Click here to Skip to main content
14,641,293 members
Rate this:
Please Sign up or sign in to vote.
Hello

I need to ask for admin rights during runtime of my application.
I want to do so, because I need to change registry.
I don't want to ask for it via manifest, because it asks at app start, not when needed only.

How can I do it? Is there any function for that?

Thanks!

What I have tried:

Searching google ^^
I found a manifest way to do so, but I don't want to use it (reason above). I hope it is not the only way.
Posted
Updated 4-May-16 9:23am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

It is impossible to do for the already executing process. You can only start one more process (even if this is the same application). Another approach is to add appropriate application manifest which would force the runtime system to request the user for UAC elevation confirmation from the very beginning.

For the first approach, please see: CreateProcessAsUser function (Windows)[^].

For the second (manifest) approach, please see, for example, this answer: C++ — How to run application with Admin privileges using Manifest file in Visual Studio 2005?[^].

Note that it is impossible to elevate the privileges without explicit user's consent. If it was possible, it would defeat the purpose of UAC. Please see: User Account Control — Wikipedia, the free encyclopedia[^].

—SA
   
v3
Comments
Cansisti 4-May-16 15:27pm
   
Where can I find such manifest?
   
You add it and set up its options. I referenced the answer on that for Visual Studio, which sets up the project options for that.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100