vs2008中向项目(以C#为例)添加要求管理员权限的属性(为了兼容vista的UAC)

来源:互联网 发布:天津广电网络机顶盒 编辑:程序博客网 时间:2024/06/07 21:36

两天做了一个小程序, 需要管理员权限, 用过vista 的肯定知道, 在UAC 打开的情况下, 一个需要管理员权限的程序图标上会有一个盾, 在运行程序的时候会跳出确认对话框, 如何让自己的程序也做到这一点呢?

流程:

1. 向项目中添加一个manifest 文件, 如下图所示:

2. 打开这个文件, 可以看到类似下面的代码, 在requestedExecutionLevel 节中, 把level 的值改为requireAdministrator, 如下所示,  (与默认的代码相比, 只改了这一点) 重新编译即可. 

<?xmlversion="1.0"encoding="utf-8"?>
<asmv1:assemblymanifestVersion="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">
<assemblyIdentityversion="1.0.0.0"name="MyApplication.app"/>
<trustInfoxmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivilegesxmlns="urn:schemas-microsoft-com:asm.v3">
<!--UAC
Windows
requestedExecutionLevel
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />

requestedExecutionLevel
-->
<requestedExecutionLevellevel="requireAdministrator"uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</asmv1:assembly>
原创粉丝点击