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.
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.
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