Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run the Qt application as administrator on Windows

Is there a way I can run the Qt application as an administrator? I have an auto-updater for my application. It needs administrator privileges to replace the files in Program Files folder and hence it requires administrator privileges.

like image 728
ssk Avatar asked May 29 '12 16:05

ssk


1 Answers

Running your application with administrator privileges does not have a whole lot to do with Qt. There are two approaches.

The "simple" one is to manually set your application to run with administrator privileges. You can do so by right-clicking on the executable. Then on the "Compatibilty" tab, you can choose to "Run this application as an administrator" under "Privilege level".

However, if you automatically want to achieve the same, you will have to embed a manifest into your application. What you're looking for is to set the requestedExecutionLevel to requireAdministrator. A bit more information can be found on MSDN or in this Wikipedia entry on UAC.

For your application as built in Qt Creator, it means you will need to embed the manifest by including a reference to it in a Resource (.rc) file. This resource file can then be added to your .pro file by specifying RC_FILE = myapp.rc. An informative blog post on this very issue is this one, as well as this post on the QtCentre forum.

like image 152
Bart Avatar answered Sep 27 '22 19:09

Bart