由于程序需要管理员权限,在VC6下面的做法如下:
1.在/res目录下建立任意文件名的*.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="programname.exe.manifest"
type="win32"
/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
2.在资源中导入这个文件,资源类型24,资源ID为1即可
但是工程导入到VS2010后编译出错,如下信息
Manifest Authoring error c1010001:Attribute values in different manifest snippets not equal.
原因是VS2010本身就有权限管理的设置,在工程属性-->Configuration Properties-->Linker-->Manifest File-->UAC Execution Level-->requireAdministrator
修改此处即可
附上几个相关网址:
Application Manifest
http://msdn.microsoft.com/en-us/library/dd371711.aspx
http://www.cnblogs.com/absolute8511/archive/2011/05/29/2061519.html
避免c++程序在windows7或vista下关闭后出现程序兼容性助手
http://www.cnblogs.com/zhyong/archive/2011/08/09/2131815.html