您的位置:首页 > 编程语言 > C#

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

2014-02-12 13:16 429 查看


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

两天做了一个小程序, 需要管理员权限, 用过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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐