C++: Run program as administrator

If you want create application with administrator privileges (on windows operating system) like this picture:

You can follow this instructions:
First open your c++ project on visual studio (example I use visual studio 2013), then right click the project and click properties (ALT + Enter).
And then select Configuration PropertiesLinkerManifest file like this picture:

And now change UAC Execution Level with this requireAdministrator (/level=’requireAdministrator’) and UAC Bypass UI Protection with No (/uiAccess=’false’) as in the picture above.

And the last, you can compile your project and see the changes, you will get icon administrator privileges in your application like the first picture in this content.
Actually, with your added administrator privileges, you create manifest file. Source code of the manifest file is as follows:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false"></requestedExecutionLevel>
      <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity>

But in this case, the manifest file is embedded directly in the application. So if you want have manifest file like this picture:

So open again project properties (ALT + Enter) and select Configuration PropertiesManifest ToolInput Output and change Embed Manifest from yes to No:

Klik OK and build again your project..

  1. http://stackoverflow.com
  2. http://msdn.microsoft.com/en-us/library/ms235229.aspx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s