Win7/8 是以一份程序集清单 Assembly Manifest 文档来获取程序需要的权限信息的,这份清单可以以资源形式内嵌入应用程序,也可以以外置文件形式来和程序放置在一起,如果你能够重新编译程序,则建议使用第一种,使用内嵌式程序清单的程序在 Win7/8 中的图标会有盾牌标志,而使用外置形式则没有。
程序集清单的内容如下:
<?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="test.exe.manifest"
type="win32"
/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
/////////////////////////////////////////////////////////-----------------------------------///////////////////////
其中,name="test.exe.manifest"名字可以随意,但是更改为自己软件的名字最好。
上述清单指定了该程序运行需要管理员权限,如果需要使用其他权限,则可以用以下三者之一替换其中的 requestedExecutionLevel 节点。
<!-- 普通权限 -->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<!-- 管理员权限 -->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<!-- 最高权限 -->
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
对于外置程序集清单,可以将上述内容的文件以 应用程序名.Manifest 的文件名和程序放置在同一目录下即可,比如名为 test.exe 的应用程序集清单应命名为 test.exe.manifest 。
接下来重点讲述第一种内嵌形式的程序集清单如何设置
在 VC6 中切换到资源视图,在资源节点上点击右键,选择 “Insert”插入新资源
,然后选择自定义资源类型 "Custom",并输入类型:24,然后在该资源上点击右键,设置资源 ID 为 1
用上述方法生成的应用程序,在 Win7/8 系统里图标会有盾牌字样,双击此应用程序,会弹出用户账户控制的提示信息。