How to enable Qt applications to run as administrator on windows

Mohammad Amir
signal slot
2 min readFeb 24, 2016

--

Some applications are required to run as administrator on windows. How Windows know that an application is to be run as administrator by default ? Well, it is done by manifest file which can be inserted inside the executable. Following is the sample manifest file which need to be inserted in application to run it as administrator.

<?xml version=”1.0" encoding=”UTF-8" standalone=”yes”?>
<assembly xmlns=”urn:schemas-microsoft-com:asm.v1" manifestVersion=”1.0">
<assemblyIdentity version=”1.0.0.0" processorArchitecture=”X86" name=”applicationname” type=”win32"></assemblyIdentity>
<description>Description of application</description>
<! — Identify the application security requirements. →
<trustInfo xmlns=”urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level=”requireAdministrator” uiAccess=”false”></requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

Following are steps to insert this manifest inside application in Qt projects

  1. Save the above xml to manifest.xml
  2. Add following into the PRO file (Qt project file)
win32 {
QMAKE_POST_LINK += mt -nologo -manifest $$PWD/manifest.xml -outputresource:$$OUT_PWD/$$TARGET”.exe” $$escape_expand(\n\t)
}

Adding above lines in pro file will execute following command after build to insert the manifest in the application.

mt -manifest manifest.xml -outputresource:application.exe

Please make sure that manifest file and executable path is given correctly. It can be different in your project settings so please update it accordingly.

After this the executable will have a shield overlay icon on it and whenever you start it will be started as administrator.

Hope this helps !

--

--

Mohammad Amir
signal slot

Technology enthusiast and software consultant. Contact me at amir.zilli@gmail.com Skype: amir.zilli