Qt 程序默认管理员权限运行

解决方案一

在pro文件中添加
QMAKE_LFLAGS += /MANIFESTUAC:"level='requireAdministrator'uiAccess='false'"

解决方案二

假设需要管理员权限的程序为MyApp.exe

把MyApp.exe,MyApp.exe.manifest,mt.exe放到同一个目录,打开命令提示符,cd到该目录,执行下面命令

mt.exe -manifest "MyApp.exe.manifest" -outputresource:"MyApp.exe";#1

MyApp.exe.manifest参考内容如下

 1 <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
 2 <assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
 3   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
 4     <security>
 5       <requestedPrivileges>
 6         <requestedExecutionLevel level='requireAdministrator' uiAccess='false' />
 7       </requestedPrivileges>
 8     </security>
 9   </trustInfo>
10 </assembly>

mt.exe在C:Program FilesWindows Kits下,装过visual studio的。

为了方便,做成批处理,下载:QT管理员权限补丁

原文地址:https://www.cnblogs.com/ybqjymy/p/13612722.html