自Vista和Windows 7问世以来,我的一些.NET应用程序开始抛出安全异常.
我注意到一些应用程序(即我的防病毒软件,控制面板)有一个小屏蔽,当我运行这些应用程序时,Windows会自动向我请求管理员权限.
我知道作为用户,我可以将应用程序设置为以管理员身份运行,但这不够好,因为如果应用程序将在没有权限的情况下运行,那么它将在我的用户计算机上崩溃.
有没有办法告诉Windows(以编程方式)我希望应用程序以管理权限运行?
DSO*_*DSO 16
创建应用程序清单,将requestedExecutionLevel设置为requireAdminstrator:
示例(在添加Application Manifest时由VS生成):
<?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 Manifest Options
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>
</asmv1:assembly>
Run Code Online (Sandbox Code Playgroud)
如果将其添加到Visual Studio应用程序项目中,则在编译时它将嵌入到程序集中.
归档时间: |
|
查看次数: |
11913 次 |
最近记录: |