利用manifest提升程序为VISTA/WIN7管理员权限

建立文本文件, 命名为”可执行文件名.exe.manifest”,并加入以下代码:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="VistaLogoDemo" type="win32"/>
<description>Description of your application</description>
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
运行级别有3种,这里使用 requireAdministrator 表示以管理员权限运行,如果写为 aslnvoker,那么就是以普通权限运行。
将该文件存放运行文件目录下
在VS中加载程序EXE


添加资源导入manifest文件命名为RT_MANIFEST,将其ID改为1
保存exe。
这样在V或7下就会有盾牌标志,程序启动会提示UAC而管理员权限启动


 
<http://hi.baidu.com/cannotforget/item/4619afc285331547a9ba94c8>

猜你喜欢

转载自blog.csdn.net/ptrunner/article/details/16809097