vs2008中向項目(以C#爲例)添加要求管理員權限的屬性(爲了兼容vista的UAC)

文章轉載:http://moosdau.blog.163.com/blog/static/4371128200882231911531/

這兩天做了一個小程序, 需要管理員權限, 用過vista 的肯定知道, 在UAC 打開的情況下, 一個需要管理員權限的程序圖標上會有一個盾, 在運行程序的時候會跳出確認對話框, 如何讓自己的程序也做到這一點呢?

流程:

1. 向項目中添加一個manifest 文件, 如下圖所示:

2. 打開這個文件, 可以看到類似下面的代碼, 在requestedExecutionLevel 節中, 把level 的值改爲requireAdministrator, 如下所示,  (與默認的代碼相比, 只改了這一點) 重新編譯即可. 

<?xml version="1.0" encoding="utf-8"?>
<
asmv1:assembly manifestVersion="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">
<
assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<
trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<
security>
<
requestedPrivileges xmlns="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
-->
<
requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</
requestedPrivileges>
</
security>
</
trustInfo>
</
asmv1:assembly>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章