zoukankan      html  css  js  c++  java
  • C# 让程序自动以管理员身份运行

    在程序中加入MANIFEST资源: 

    1) 打开Vs2005或vs2008工程,看在Properties下是否有app.manifest这个文件;如没有,右击工程在菜单中选择“属性”,出现界面如下:

    选中"Security",在界面中勾选"Enable ClickOnce Security Settings"后,在Properties下就有自动生成app.manifest文件。

    打开app.manifest文件,将

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

    改为

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

    修改后的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 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>
          <applicationRequestMinimum>
            <defaultAssemblyRequest permissionSetReference="Custom" />
            <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
          </applicationRequestMinimum>
        </security>
      </trustInfo>
    </asmv1:assembly>

    然后在"Security"中再勾去"Enable ClickOnce Security Settings"后,重新编译即可。

  • 相关阅读:
    用django2.1开发公司官网(上)
    vue常用手册
    xadmin+django2.0删除用户报错,get_deleted_objects() takes 3 positional arguments but 5 were given
    Vue+koa2开发一款全栈小程序(9.图书详情页)
    Vue+koa2开发一款全栈小程序(8.图书列表页)
    Vue+koa2开发一款全栈小程序(7.图书录入功能)
    Vue+koa2开发一款全栈小程序(6.个人中心)
    Vue+koa2开发一款全栈小程序(5.服务端环境搭建和项目初始化)
    java中基本类型double和对象类型Double
    vb中的除法
  • 原文地址:https://www.cnblogs.com/jifeng/p/2571654.html
Copyright © 2011-2022 走看看