码迷,mamicode.com
首页 > Windows程序 > 详细

安装包中DLL文件在WIN7下不能正常注册的解决方案

时间:2015-04-18 13:05:54      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

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

1. 直接修改exe属性:

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

 

 

技术分享

 

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

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

1) C#:

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

技术分享

 

 

?         选中“安全性”,在界面中勾选“启用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盾牌标志了。

安装包中DLL文件在WIN7下不能正常注册的解决方案

标签:

原文地址:http://www.cnblogs.com/moonwind/p/4437187.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!