zoukankan      html  css  js  c++  java
  • QT使用UAC(经过验证)

    网上有很多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

    参考:http://stackoverflow.com/questions/7744410/how-to-execute-an-app-without-elevation

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

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

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

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

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

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

  • 相关阅读:
    Python len() 方法
    Python join() 方法
    Python isupper() 方法
    使用quartz进行容器启动时登陆接口服务器和接口服务器进行心跳连接
    实现锁死的有滚动条的div的表格(datagird)
    使用spring的事务的三种方法
    webservice系统学习笔记7-使用handler实现过滤器/拦截器效果
    webservice系统学习笔记7-异常处理
    webservice系统学习笔记6-使用soap的header传递消息
    JSTL fmt:formatNumber 数字、货币格式化
  • 原文地址:https://www.cnblogs.com/findumars/p/4539686.html
Copyright © 2011-2022 走看看