zoukankan      html  css  js  c++  java
  • Winform 获取Win7 UAC 管理员权限

    1.新建app.manifest 写入配置内容  

    <?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 节点。
            -->
            <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
          </requestedPrivileges>
        </security>
      </trustInfo>
      <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
        <application>
          <!-- 此应用程序设计使用的所有 Windows 版本的列表。Windows 将会自动选择最兼容的环境。-->
          <!-- 如果应用程序设计使用 Windows 7,请取消注释以下 supportedOS 节点-->
          <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
        </application>
      </compatibility>
      <!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
      <!-- <dependency>
        <dependentAssembly>
          <assemblyIdentity
              type="win32"
              name="Microsoft.Windows.Common-Controls"
              version="6.0.0.0"
              processorArchitecture="*"
              publicKeyToken="6595b64144ccf1df"
              language="*"
            />
        </dependentAssembly>
      </dependency>-->
    </asmv1:assembly>


    2.修改requestedExecutionLevel 中的level

    3.在项目属性中选择应用程序项,然后在清单中选择刚才加入的文件app.manifest。

    4.重新编译程序

    5.在bin下运行程序可以看到图标下已经出现标识

  • 相关阅读:
    课程安排及脉络
    面向对象 魔法方法 单例(五)
    练习项目:选课系统
    面向对象 多态 类方法 反射 (四)
    面向对象(三) 组合 封装
    面向对象编程(二)
    面向对象编程(一)
    python入门总复习
    模块(四)
    模块(三)
  • 原文地址:https://www.cnblogs.com/midcn/p/2658026.html
Copyright © 2011-2022 走看看