How do I make a console app always run as an administrator?

Marco picture Marco · Mar 13, 2013 · Viewed 25.6k times · Source

I have a console application that was developed to be called by a erp software.

They call my app inside the erp and when they do it, i always get errors related to the insufficient permission to do it.

I have checked the "run this program as an administrator" checkbox in the properties of the exe for all users but the result is the same.

I have read something about adding a manifest that will make the app prompt for the uac dialog, but thats not what i want because the app will be called from erp on the server and clients will not see the dialog on server.

Can someone explain me how to make this console app always run as administrator?

Answer

Alexey picture Alexey · Mar 13, 2013

Add into your project Application Manifest File (Add -> New Item -> General -> Application Manifest File) and add the below node into the app.manifest:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx