Vista 和 Windows
默認的配置如下
<asmv
xmlns:asmv
xmlns:xsi="
<assemblyIdentity version="
<trustInfo xmlns="urn:schemas
<security>
<requestedPrivileges xmlns="urn:schemas
<!
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</asmv
我們可以看到這個配置中有一個 requestedExecutionLevel 項
Value
Description
Comment
asInvoker
The application runs with the same access token as the parent process
asInvoker : 如果選這個
highestAvailable: 這個是以當前用戶可以獲得的最高權限運行
requireAdministrator: 這個是僅以系統管理員權限運行
默認情況下是 asInvoker
highestAvailable 和 requireAdministrator 這兩個選項都可以提示用戶獲取系統管理員權限
他們的區別在於
關於requestedExecutionLevel 設置的權威文檔請參考下面鏈接
Create and Embed an Application Manifest (UAC)
下面是修改後的配置文件<?xml version="
<asmv
xmlns:asmv
xmlns:xsi="
<assemblyIdentity version="
<trustInfo xmlns="urn:schemas
<security>
<requestedPrivileges xmlns="urn:schemas
<!
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</asmv
配置文件修改後
下面再來看看程序如何知道當前運行在系統管理員權限還是非系統管理員權限
using System
{
WindowsIdentity identity = WindowsIdentity
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal
}
這段代碼可以用於判斷當前程序是否運行在系統管理員權限下
From:http://tw.wingwit.com/Article/program/net/201311/14263.html