Qt(在Windows上)将权限级别设置为“requireAdministrator”

我正在使用Qt Creator,努力使.exe文件以pipe理员身份运行。

通过在线阅读所有的解决scheme,我试图把这一行放在我的.pro文件中:

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

但仍然当我检查我的.exe (使用记事本)它包含:

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

有人可以告诉我,如何添加requireAdministrator

临时解决scheme:直到现在我找不到一个解决scheme,所以我做了一个临时的黑客攻击。 我做了一个名为“LaunchAnother.exe”的.exe文件,它将使用以下代码启动我的“main.exe”:

 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); } 

还在等待更好的解决scheme。

您可以使用mt.exe在编译后嵌入清单文件。

创建和嵌入应用程序清单(UAC)

如何:在C / C ++应用程序中嵌入一个清单

示例清单文件

另一种选择是创建一个.res文件,并将其指向您的清单文件,如下所示:

如何仅用mingw工具将清单嵌入到dll中

希望有所帮助。