Qt(在 Windows 上)将权限级别设置为“requireAdministrator"; [英] Qt (on Windows) setting privilege-level to "requireAdministrator"
问题描述
我正在使用 Qt Creator 并努力使 .exe
文件默认以管理员身份运行.
I am using Qt Creator and struggling to make the .exe
file to run as administrator by default.
在线阅读所有解决方案后,我尝试将此行放在我的 .pro
文件中:
Reading through all the solutions online I tried to put this line in my .pro
file:
QMAKE_LFLAGS += /MANIFESTUAC:"level='requireAdministrator' uiAccess='false'"
但是当我检查我的 .exe
(使用记事本)时它仍然包含:
But still when I check my .exe
(using notepad) it contains:
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
谁能告诉我,如何添加requireAdministrator
?
Can someone tell me, How to add requireAdministrator
?
临时解决方案:直到现在我找不到解决方案所以我做了一个临时黑客.我做了一个 .exe
叫做'LaunchAnother.exe' 这将使用以下代码启动我的 'main.exe':
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.
推荐答案
您可以使用 mt.exe 编译后嵌入清单文件.
You can embed the manifest file after compilation using mt.exe.
另一种选择是创建一个 .res 文件并将其指向您的清单文件,如下所示:
Another option is to create a .res file and point that to your manifest file as shown here:
希望有所帮助.
这篇关于Qt(在 Windows 上)将权限级别设置为“requireAdministrator";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!