[SOLVED] Requesting administrator rights on Windows 8 is not working



  • Hello,

    I'm using the following line in my .pro file to make the program request admin rights:
    @QMAKE_LFLAGS += /MANIFESTUAC:"level='requireAdministrator' uiAccess='false'"@

    However, when the program is compiling I get the following error:
    :-1: error: error: /MANIFESTUAC:level='requireAdministrator' uiAccess='false': No such file or directory

    Are there any additional steps I'm missing? I've tried cleaning the project and running qmake without success.

    Thanks!



  • Hi it sure looks correct to me. I just tried a new empty Widgets app, added your QMAKE_LFLAGS at the end of the .pro file, and sure enough Windows displays the UAC prompt when I start the app.

    My setup: 32-bit Qt 5.3.2 on Visual Studio 2013 Update 3 on 64-bit Windows 8.1. Perhaps you're using MinGW?



  • Yes I am, I've just left it as default. Do I need to switch?



  • Yeah, it seems the MinGW toolchain (specifically ld.exe) doesn't support stuffing a custom Windows manifest into the .exe file, you could do it manually using a hex editor or you could switch to Visual Studio.


  • Moderators

    With mingw you need to create app manifest requiring elevated rights by hand and either embed it after the creation of exe with a third party tool (eg. mt.exe from Microsoft) or as a resource (.res, not the .qrc of Qt ). I wouldn't go as far as stuffing it with hex editor but I can imagine there are people who do :)

    "Here":http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx is an example manifest and the command line for mt.exe (near the bottom of the article):



  • You younger people, always lazy using a tool (mt.exe) when instead you can be a real man and fire up a hex editor.

    Just kidding! Thanks Chris, I should have guessed there was a handy tool available. Perhaps possible to include in QtCreator's build process?


  • Lifetime Qt Champion

    Could be the subject of a feature request ;)



  • Indeed SGaist, it's a good idea, it would increase the value of the MinGW toolchain as used by Qt.

    (You can of course add the invocation of mt.exe as a custom process step to be run after mingw32-make.exe yourself, but if it's a built-in feature so much better. Also it could be used for Visual Studio installations as well, then you wouldn't have to include that QMAKE_LFLAGS line shown above.)

    Finally, I think for manifests to work 100% with mingw, it needs to loose its "dependency on msvcrt.dll":http://blogs.msdn.com/b/oldnewthing/archive/2014/04/11/10516280.aspx.



  • Thanks for all the suggestions!

    I've switched to the MSVC compiler and it is working now, however a built-in tool to do this would definitely be useful!

    Consider this solved :)


  • Lifetime Qt Champion

    I'll let you guys create the request since you already have the complete process at hand that could be added to Qt Creator


  • Moderators

    I don't think that's a good idea. mt.exe is part of the MS toolchain and the whole idea of MinGW is to use an alternative. If you install MS toolchain you might as well use MSVC and avert the whole thing.

    Apps requiring admin rights are not (or rather should not be) that common and, as I said, you can also just embed the manifest in the resource file (which you will probably create on Windows anyway, if only for the exe icon and version info).

    @hskoglund - the msvcrt debate is as long as the history of MinGW itself. I wish this could be fixed but either side wasn't willing to do that for years - MS won't finally remove the file from the OS because of backwards compatibility and MinGW won't stop using it because they didn't port libc to Windows yet (it's been like that for years now).
    The MinGW toolchain is lacking a lot in my opinion. Few tools, codegen of MSVC is better, the std library issue... The only argument to use it I can think of is better C++11/14 support.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.