zoukankan      html  css  js  c++  java
  • 20121122 11:23 vc编写以管理员权限运行的程序

    如果是vs2008或者2010,就比较简单了,直接项目右键---属性---连接器---清单文件---uac执行级别 选择requireAdministrator 重新编译 这样你的程序直接运行就拥有管理员权限了。程序就会出现一个盾牌。

    =======================================其他编译器的方法:

    导入manifest文件

    1.如果你使用的是VC6或者vs2003,,2005,通过导入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>

        </security>

      </trustInfo>

    </asmv1:assembly>

    注:此文件只要扩展名是.manifest文件名可以任意。文件内容的name属性值也可以为任意。(VC6.0下经过测试)

    2.把此文件"import"到资源文件中,资源类型为24,资源ID为1,

    注:经测试资源类型必须为24,资源ID也必须为1,

    该代码添加到VC资源中即可, 添加方式:

    =============================添加方法:

    添加一个“custom”资源,”resource type”填24,把资源ID改为1

    如果只有一个可执行文件,也可以通过以下方法添加:

    mt.exe -manifest e4nmgr.exe.manifest -outputresource:e4nmgr.exe;1

    =============================

    3.重新编辑即可,在windows7下该程序图标有一个盾状小图标,双击运行会出现对话框要求提升为管理员权限。

    参考:

    http://hi.baidu.com/aoedebug/blog/item/0d6c26fc5c700ec2f3d3854d.html

    http://msdn.microsoft.com/en-us/library/bb756929.aspx

    http://www.vista123.com/html/6718.html

  • 相关阅读:
    canvas 画一个钟表
    .net防止写文件线程冲突
    .net中params以前没关注过的一个现象
    dom属性和特性
    数组常用方法
    新手配置vux
    改变placeholder的字体颜色大小
    设置cookie,删除cookie,读取cookie
    css 画三角形
    audio元素和video元素在ios和andriod中无法自动播放
  • 原文地址:https://www.cnblogs.com/libao/p/2793225.html
Copyright © 2011-2022 走看看