码迷,mamicode.com
首页 > 其他好文 > 详细

QT使用UAC(经过验证)

时间:2015-05-30 00:40:55      阅读:479      评论:0      收藏:0      [点我收藏+]

标签:

网上有很多manifest的版本,mingw与vs系列也有不同的解决方案,不管那么多,我是使用这篇文章解决这个问题的:

So it turns out that I had another bug that caused the non-elevated running branch to run in all cases. The model I described in the post works. To avoid Windows infering the need for elevated permissions, you need to add a manifest resource. (for example, if the name of your application exe contains the word "updater" it will be triggered)

The contents of the manifest are the following:

<?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>

Compiling it to your .exe depends on your compiler and environment, so I‘m only showing mine: Qt Creator and mingw-gcc:

Create an rc file for the resources with the following content:

1 24 DISCARDABLE manifest.xml

Add this rc file to your .pro like this:

win32:RC_FILE = resources.rc

After this, ShellExecute without the verb paramter will run without elevation, and using "runas" will run it with elevation.

经过亲自验证,确实有效。我使用win7 x64, mingw, qt5.32,其中参数asInvoker有可能需要改成requireAdministrator

---------------------------------------------------------

另一篇探测UAC是否已经开启,有点意思:

http://www.qtcn.org/bbs/read-htm-tid-48310.html

---------------------------------------------------------

这篇比较详细,看上去很认真的样子,但是我没有成功,但是仍然记录一下:

http://blog.chinaunix.net/uid-14281179-id-3394558.html

QT使用UAC(经过验证)

标签:

原文地址:http://www.cnblogs.com/findumars/p/4539686.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!