Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for the executable to ask for Administrator rights? (Windows 7)

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.

like image 397
Renan Greinert Avatar asked Jan 18 '12 18:01

Renan Greinert


People also ask

Why does Windows 7 keep asking me for administrator permission?

In most of the cases, this issue occurs when the user doesn't have sufficient permissions to access the file. So I would suggest you to take ownership of the file and then check if the issue persists.


Video Answer


1 Answers

You cannot acquire elevated privileges after the process has started. Your options are:

  1. Put the part of your application that requires elevated privileges into a separate process and manifest that with requireAdministrator.
  2. Run the part of your application that requires elevated privileges as an out-of-proc COM object.
like image 151
David Heffernan Avatar answered Sep 22 '22 17:09

David Heffernan