• 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

  • 相关阅读:
    关于Android的振动控制器(Vibrator)报SecurityException异常的问题
    Db4o结合Linq、Lambda表达式的简单示例
    递归选取扩展方法(RecursionSelect)的新重载形式
    解决Adobe Illustrator CS5启动后自动关闭的问题
    趋势畅想搭载android系统的智能数码相机
    Android SurfaceView 绘图及帧频处理方法修正
    MVP 模式实例解析
    .Net 自定义应用程序配置
    C# 类型基础
    [译]开闭原则
  • 原文地址:https://www.cnblogs.com/findumars/p/4539686.html
Copyright © 2020-2023  润新知