Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt (on Windows) setting privilege-level to "requireAdministrator"

Tags:

windows

qt

I am using Qt Creator and struggling to make the .exe file to run as administrator by default.

Reading through all the solutions online I tried to put this line in my .pro file:

QMAKE_LFLAGS += /MANIFESTUAC:"level='requireAdministrator' uiAccess='false'"

But still when I check my .exe (using notepad) it contains:

<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>

Can someone tell me, How to add requireAdministrator?

Temporary Solution: Till now I could not find a solution so I made a temporary hack. I made an .exe called 'LaunchAnother.exe' Which will launch my 'main.exe' using following code:

SHELLEXECUTEINFO shExInfo = {0};
shExInfo.cbSize = sizeof(shExInfo);
shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shExInfo.hwnd = 0;
shExInfo.lpVerb = _T("runas");                // Operation to perform
shExInfo.lpFile = _T("main.exe");       // Application to start    
shExInfo.lpParameters = "";                  // Additional parameters
shExInfo.lpDirectory = 0;
shExInfo.nShow = SW_SHOW;
shExInfo.hInstApp = 0;  

if (ShellExecuteEx(&shExInfo))
{
    WaitForSingleObject(shExInfo.hProcess, INFINITE);
    CloseHandle(shExInfo.hProcess);
}

Still waiting for a better solution.

like image 479
user739711 Avatar asked Sep 05 '12 09:09

user739711


1 Answers

You can embed the manifest file after compilation using mt.exe.

Create and Embed an Application Manifest (UAC)

How to: Embed a Manifest Inside a C/C++ Application

An example manifest file

Another option is to create a .res file and point that to your manifest file as shown here:

How to embed a manifest into a dll with mingw tools only

Hope that helps.

like image 68
phyatt Avatar answered Oct 26 '22 08:10

phyatt