【问题标题】:Qt (on Windows) setting privilege-level to "requireAdministrator"Qt(在 Windows 上)将权限级别设置为“requireAdministrator”
【发布时间】:2012-09-05 09:52:31
【问题描述】:

我正在使用 Qt Creator 并努力使 .exe 文件默认以管理员身份运行。

在线阅读所有解决方案后,我尝试将此行放入我的.pro 文件中:

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

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

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

谁能告诉我,如何添加requireAdministrator

临时解决方案: 直到现在我找不到解决方案,所以我做了一个临时破解。我做了一个.exe 叫 'LaunchAnother.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);
}

仍在等待更好的解决方案。

【问题讨论】:

  • 您的 QtCreator 是否使用 VC 工具链?您正在使用 VC 特定的开关,因此如果您的配置使用 g++,那么它根本无法工作。我还发现你可能需要添加CONFIG += embed_manifest_exe

标签: windows qt


【解决方案1】:

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

Create and Embed an Application Manifest (UAC)

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

An example manifest file

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

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

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-03
    • 2015-06-22
    • 1970-01-01
    • 2012-04-29
    • 1970-01-01
    相关资源
    最近更新 更多