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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With