Self-Elevating process
-
Hey guys,
my application needs to install MySQL on a client's system before it can be started. I do that by calling msiexec via QProcess. To install MySQL properly the process need administrative rights of course. At the moment I simply check the error message if the process can not run due to insufficient privileges and show a message box telling the user to restart the program by cklicking "run as administrator".
What I am trying to achieve is a self-elevating process that claims the administrative rights by himself. Are the any native Qt methods to achieve that or do I have to use the windows uac libraries? If the last one is the case does someone has a simple example?
Thanks a lot
-
Hi
The Qt installer frame can install as admin so would maybe run it for you.
https://forum.qt.io/topic/35272/qt-installer-framework-and-administrator-privileges-solved/8else as far as i know you need a manifest
https://msdn.microsoft.com/en-us/library/bb756929.aspxas if a process could just run as admin the whole UAC concept would kind a fall apart :)
So I must confess, I like your solution a lot as its so simple.
-
@mrjj
HiThe Qt install would be a solution but I am using a license management for my software where the client has to provide a valid license key before the software does anything. Therefore the installation of MySQL has to take place afterwards and within the program.
I had the solution with the manifest in mind, but this means that the whole program runs in admin-mode which is not necessary and - in case of any errors in the code - dangerous too.
A self-elevation only means that the program automatically asks for admin rights and the user still have to accept the uac question ;). It just means that the user can skip the "restart manually as admin"-part.
-
@SebastianS
Ok. Not used Installer that much so I dont know if it can handle lic keys too.
Also it seems like a overkill.I understood you wrong. :)
Last time I had to do something similar , I used autoit and created exe and used that.
You can see the actual windows API calls. And maybe use that for starting point.
Sorry I dont have c++ version.
Maybe you find it useful.
https://www.autoitscript.com/forum/topic/145697-_isuacadmin-check-admin-and-elevation-rights/
would be easy to let it start your installer. -
@SebastianS
well it does call the API directly so its very close.
I was lazy and just made script to ask and run my exe.
The AutoIt compiler can make exe from file so no script runtime is needed and its very small.
But yeah, it should be fairly easy to convert since its fairly normal syntax and uses both API and
types a c++ version would.