zoukankan      html  css  js  c++  java
  • 安装包中DLL文件在WIN7下不能正常注册的解决方案

    exe在Vista或Win7下不以管理员权限运行,会被UAC(用户帐户控制)阻止访问系统某些功能,如修改注册表操作等;如何让exe以管理员权限运行呢,方法有两种,一个是直接修改exe属性;另一个是在程序中加入MANIFEST资源,下面分别介绍。

    1. 直接修改exe属性:

    1) 右击“exe”,在弹出的菜单中选择“属性”,出现的界面如下图:

     

     

    exe在Vista或Win7下以管理员权限运行——C与Delphi解决方案 - 海风 - 海风的博客

     

    2) 选择“兼容性”项,并勾选“以管理员身份运行此程序”项即可。

    2. 在程序中加入MANIFEST资源,分C#和delphi实现方法:

    1) C#:

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

    exe在Vista或Win7下以管理员权限运行——C与Delphi解决方案 - 海风 - 海风的博客

     

     

    ?         选中“安全性”,在界面中勾选“启用ClickOnce安全设置”后,在Properties下就有自动生成app.manifest文件。

    打开app.manifest文件,在<security>下加入

    <requestedPrivileges>

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

          </requestedPrivileges>,重新编译即可,

    全部代码如下所示:

    <?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">

      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">

        <security>

          <applicationRequestMinimum>

            <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />

            <defaultAssemblyRequest permissionSetReference="Custom" />

          </applicationRequestMinimum>

          <requestedPrivileges>

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

          </requestedPrivileges>

        </security>

      </trustInfo>

    </asmv1:assembly>

    2) Delphi:Delphi程序必须在资源里面嵌入MANIFEST信息。

    ?         首先编辑一个文件,内容如下:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 

    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">

        <security>

          <requestedPrivileges>

            <requestedExecutionLevel level="requireAdministrator"/>

          </requestedPrivileges>

        </security>

    </trustInfo>

    </assembly>

    保存为UAC.manifest,这里文件是随意的。特别注意红色的“requireAdministrator”,这个表示程序需要管理员(Administrator)才能正常运行。

    ?         然后编辑一个RC文件,名称为uac.rc 如下所示:

    1 24 UAC.manifest

    其中:

    1-代表资源编号

    24-资源类型为RTMAINIFEST

    UAC.manifest-前面的文件名称

    ?         用brcc32编译这个rc文件为res文件,如下所示:

    brcc32 uac.rc -fouac.res

    ?         在程序里面加入

    {$R uac.res}

    让Delphi编译的时候,把uac.res编译进exe文件

    ?         把文件放到vista或win7下运行,就会看程序图标下面显示UAC盾牌标志了。

  • 相关阅读:
    《C++ Primer Plus》15.1 友元 学习笔记
    《C++ Primer Plus》14.4 类模板 学习笔记
    《C++ Primer Plus》14.3 多重继承 学习笔记
    《C++ Primer Plus》14.2 私有继承 学习笔记
    《C++ Primer Plus》第13章 类继承 笔记
    继承和动态内存分配——需要为继承类定义 显式析构函数、复制构造函数和赋值运算符
    C++中的抽象基类示例
    C++ 在继承中使用virtual
    《C++ Primer Plus》第12章 类和动态内存分配 学习笔记
    《C++ Primer Plus》12.7 队列模拟 学习笔记
  • 原文地址:https://www.cnblogs.com/moonwind/p/4437187.html
Copyright © 2011-2022 走看看