Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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
 
Share this answer
 
v3
Comments
Cansisti 4-May-16 15:27pm    
Where can I find such manifest?
Sergey Alexandrovich Kryukov 4-May-16 15:30pm    
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900