.NET提升应用程序在windows vista和windows 7中的UAC权限

1.打开应用程序的解决方案。

2.右键单击程序所在项目,选择 '添加'-->'新建项'。

3.在弹出的窗口中选择 '应用程序清单文件' 点击添加。

4.下面是生成的应用程序清单文件的代码:

<?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="asInvoker" uiAccess="false" />

      </requestedPrivileges>

    </security>

  </trustInfo>

</asmv1:assembly>

把代码中的<requestedExecutionLevel  level="asInvoker" uiAccess="false" />改为<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />然后重新生成解决方案。

5.重新运行应用程序便会弹出提升权限的对话框了。

转载于:https://my.oschina.net/secyaher/blog/274449

猜你喜欢

转载自blog.csdn.net/weixin_33805743/article/details/91966994