Reputation: 3436
I am developing a partition disk program, and for me to read the \\\\.\\PhysicalDrive0
I need admin rights.
I am wondering if it is possible, in the run time, for the program to gain admin rights? Is there any win api for that?
I want to do that because I want the program to execute with admin rights only when it is reading/writing the disk. For security reasons, I don't want the program to execute all the time with admin rights, because someone could find a bug (stack or heap overflow for example) in some module and execute arbitrary commands as adm.
Upvotes: 11
Views: 7823
Reputation: 57764
I have never seen a way to transition rights once a process has begun executing. The only way I know of is for the process to be created as privileged.
I look forward to other answers in case there is another way.
(update)
The article Teach Your Apps To Play Nicely With Windows Vista User Account Control (about halfway down) confirms that admin rights can be granted only at process creation time.
Upvotes: 4
Reputation: 572
Project's Propeties (Alt + Enter) ->
Linker ->
Manifest File
->
UAC Execution level (in VS2015, in 2010 it's similar)
->
requireAdministrator or highestAvailable
Edit: Also, if it's updating program, simply make your program's name starting with Update
and Windows will automatically recognize it.
Upvotes: 0
Reputation: 612794
You cannot acquire elevated privileges after the process has started. Your options are:
requireAdministrator
.Upvotes: 14
Reputation: 13130
You need to embed manifest with requireAdministrator flag
http://msdn.microsoft.com/en-us/library/bb756929.aspx
Upvotes: 1