How to run application in Qt as administrator?
2015-07-21 10:03
549 查看
在windows中使用Qt Creator编译出需要管理员权限来运行的程序,分为3个步骤:
1. 新建一个xml文档,例如命名为uac.manifest
注:level的取值,requireAdministrator、asInvoker或highestAvailable
2. 新建一个Resource File,例如命名为uac.rc
3. 在Qt project中(即pro文件)添加以下内容:
然后编译出的程序,就需要管理员权限来运行了。
1. 新建一个xml文档,例如命名为uac.manifest
<?xml version="1.0" encoding="utf-8"?> <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <!-- UAC Manifest Options If you want to change the Windows User Account Control level replace the requestedExecutionLevel node with one of the following. <requestedExecutionLevel level="asInvoker" uiAccess="false" /> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> If you want to utilize File and Registry Virtualization for backward compatibility then delete the requestedExecutionLevel node. --> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> </requestedPrivileges> </security> </trustInfo> </asmv1:assembly>
注:level的取值,requireAdministrator、asInvoker或highestAvailable
2. 新建一个Resource File,例如命名为uac.rc
#include <windows.h> //这句不能少 CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "uac.manifest"
3. 在Qt project中(即pro文件)添加以下内容:
RC_FILE = uac.rc
然后编译出的程序,就需要管理员权限来运行了。
相关文章推荐
- android从系统图库中取图片的实例代码
- 在Cocos2d-Lua中使用ProtoBuf (Xcode配置方法)
- Android典型界面设计——FragmentTabHost+Fragment实现底部tab切换
- [寒江孤叶丶的Cocos2d-x之旅_35]在Cocos2d-Lua中使用ProtoBuf (Xcode配置方法)
- Unity3D脚本-C#
- Android Studio SDK 更新问题
- xml布局内容总结(一)--Android
- ios7-21数组
- Android中View的绘制过程 onMeasure方法简述 附有自定义View例子
- [Android]使用draw9patch制作可拉伸图片
- Unity AssetBundle爬坑手记
- android通过Location API显示地址信息的实现方法
- Android开发者学习必备:10个优质的源码供大家学习
- unity3d5.0 SurvivalShooter(三) 实现动画播放代码
- objective-c 注释用法
- platform cannot apply stanford theme
- 第三波精品Android源码袭来!免费下载
- Android研究院之应用程序ListView 详解 (六)
- Android典型界面设计——FragmentTabHost+Fragment实现底部tab切换
- ProtocolBuffer在Android端的解析