解決方案一
在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 Files\Windows Kits下,裝過visual studio的。
為了方便,做成批處理,下載:QT管理員權限補丁