QT使用UAC(经过验证)
2015-05-30 00:14
363 查看
网上有很多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:
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:
Add this rc file to your .pro like this:
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
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
相关文章推荐
- PyQt4学习
- 初学Qt
- QString之arg使用一则(QTBUG19027)
- Qt5.3 For Andoid 安装过程
- Qt Creator编码设置--win7-vs2010
- 更新采购订单和销售订单qty
- QT创建透明对话框
- ubuntu12.04下Qt调试器的使用
- VS2013建立Qt程序错误处理
- Qt在Mac OS X下的编程环境搭建
- Qt环境配置
- QT 之 sendEvent & PostEvent
- qt中全局变量的用法
- PyQt4初体验
- Qt信号与槽
- QT之数据库 和 GraphicsView使用
- QT5串口通信——基础篇
- Qt中文显示
- QT共享内存使用
- Qt信号与槽工作机制--译文