Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: Run program as administrator

Some programs are automatically asking for administrator rights when you run them. These programs are marked with a little shield in the bottom right corner:
enter image description here Now I'm wondering how I could accomplish this in C++.
Is there a function for this or do I need some special compiler/linker commands for that?

like image 401
Forivin Avatar asked Oct 27 '13 12:10

Forivin


People also ask

How do I run a program as administrator in CMD?

Press Windows+R to open the “Run” box. Type “cmd” into the box and then press Ctrl+Shift+Enter to run the command as an administrator.

How do I make a program always run as administrator without password?

To do so, search for Command Prompt in the Start menu, right-click the Command Prompt shortcut, and select Run as administrator. The Administrator user account is now enabled, although it has no password.


2 Answers

Actually, this shield which means the application will need to run from administrator is set from the operating system if the application going to use any feature of that machine which needs permission from administrator.
You do not need to set anything from your app for that.
Hope the answer may help you.

like image 21
Mustakimur Khandaker Avatar answered Oct 09 '22 14:10

Mustakimur Khandaker


You must be probably looking for CreateProcessAsUser or CreateProcessWithLogonW function.

There is one more option like this:-

  • Go to the project's Property Pages dialog box.
  • Now open the Configuration Properties node.
  • Next you have to open the Linker node.
  • then select the Manifest File property.
  • Finally modify the Enable User Account Control (UAC), UAC Execution Level, and UAC Bypass UI Protection properties.

Soemthing like this:

enter image description here

And as Syam correctly mentioned in the comments the solution could be to embed a manifest in the executable.

like image 120
Rahul Tripathi Avatar answered Oct 09 '22 14:10

Rahul Tripathi