View Full Version : How to run application in qt as administrator?

19th January 2012, 06:27
How to run application in Qt as administrator? After build, instead of right click and run as administrator everytime. Once the build is over, if we just double click the app.exe. It should run as administrator automatically...

19th January 2012, 07:27
For Windows you embed an application manifest (http://msdn.microsoft.com/en-us/library/windows/desktop/aa374191%28v=vs.85%29.aspx) specifying the required requestedExecutionLevel (http://msdn.microsoft.com/en-us/library/bb756929.aspx). You will not avoid the UAC prompt if that is what you are hoping for. If you application needs to display anything in the GUI I think you also have to sign it.

For Mac. Don't know.

19th January 2012, 08:14
How to do the same using Mingw?

20th January 2012, 00:02
The same way. You write your manifest XML file, include the relevant entry in your application's RC file, and rebuild your application.

Your PRO file:

RC_FILE = coolapp.rc

Your coolapp.rc file:

#include <windows.h>

ID_ICON ICON DISCARDABLE "coolapp_desktop.ico"

Your manifest file (coolapp.exe.manifest):

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="" processorArchitecture="X86"
name="gokulnathvc.coolapp" type="win32" />
<description>Gokulnathvc Really Cool App</description>
<dependency />
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<!-- padding to four-byte multiple file size including the byte order mark -->
<!-- padding 123 -->

You will need to adapt that manifest to set the requested execution level. (You can probably ignore the comment about padding, it works around a bug with early compilers the specifics of which I cannot quite remember)

18th May 2012, 07:09
Shall we do that in project settings. instead of doing that out side.. possibility of doing that as post build.

18th May 2012, 07:52
:confused: Was there a question in there somewhere?