VB.NET写支持UAC功能的程序

来源:互联网 发布:linux下安装pyqt5 编辑:程序博客网 时间:2024/05/18 14:46

打开程序属性,查看app.manifest文件,其内容一般如下:

<?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节点。

        -->

        <requestedExecutionLevel level="requireAdministrator"uiAccess="false" />

      </requestedPrivileges>

    </security>

  </trustInfo>

</asmv1:assembly>

 Manifest文件中最重要的部分是:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

这个部分定义了当前应用程序的运行级别,其中共有三中基本如下:

    asInvoker:应用程序将使用与启动它的进程相同的权限运行。可通过选择“以管理员身份运行”将应用程序提升为更高权限。

    highestAvailable:应用程序将使用可能的最高权限级别运行。如果启动该应用程序的用户为管理员组的一个成员,则此选项与 requireAdministrator 相同。如果可用的最高权限级别高于打开进程的级别,则系统将提示提供凭据。

    requireAdministrator:应用程序将使用管理员权限运行。启动该应用程序的用户必须是管理员组的一个成员。如果打开进程未使用管理权限运行,则系统将提示提供凭据。

    uiAccess的作用是如果您希望应用程序绕过用户界面保护级别并将输入引导到桌面上的更高权限窗口(如屏幕键盘),则为 true;否则为 false。默认为 false。仅针对用户界面辅助功能应用程序设置为 true。

0 0