Qt使用UAC權限

在做Qt應用程序時,有時會需要程序以管理員身份運行,Qt下的開發方法如下。

一、mingw編譯器環境

1、添加uac.manifest文件,文件內容如下: 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
            <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
                <requestedExecutionLevel level="asInvoker" uiAccess="false" />
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>

2、添加 uac.rc文件,文件內容如下:

1 24 uac.manifest

3.pro文件中加入uac.rc文件

RC_FILE +=uac.rc

4、編譯,生成的應用程序圖標右下角帶有管理員權限的標誌。

轉載地址:https://www.cnblogs.com/findumars/p/4539686.html

二、VS編譯器環境

.pro文件中添加 QMAKE_LFLAGS配置即可,

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

參考文章:

https://blog.csdn.net/liukang325/article/details/53261346

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章