简体   繁体   English

在CAB中部署C#ActiveX以供Internet Explorer使用

[英]Deploy C# ActiveX in a CAB for Internet Explorer use

I am desperately trying to deploy an ActiveX for IE developed in C# as a CAB archive. 我拼命尝试将ActiveX for IE部署为C#开发的CAB存档。 I have read many resources (some of them from StackOverflow) and it appears a lot of people are having the same problems. 我已经阅读了许多资源(其中一些来自StackOverflow),而且似乎很多人都遇到相同的问题。 I have tried 3 solutions: a) creating a CAB VS project, b) manually creating a CAB using CABARC with a COM registration in INF and c) manually creating a CAB with launching msiexec . 我尝试了3种解决方案:a)创建一个CAB VS项目,b)使用在INF中进行COM注册的CABARC手动创建一个CAB,以及c)启动msiexec手动创建一个CAB。 None of them worked. 他们都没有工作。 I even tried d) creating a bootstrapper which launches msiexec to no avail (because some people suggested simply launching msiexec on Vista can't work). 我什至尝试过d)创建一个引导程序,该引导程序将无法启动msiexec (因为有人建议仅在Vista上启动msiexec无法工作)。

I am running Windows Vista but my project fails to run even on IE6 on XP. 我正在运行Windows Vista,但是即使在XP的IE6上,我的项目也无法运行。

When I install ActiveX using MSI, all is fine on ALL Windows. 当我使用MSI安装ActiveX时,在所有Windows上都可以。 Apparently CAB thing is not working and I could not find a proper way to debug this whole process yet. 显然,CAB无法正常工作,我还没有找到调试整个过程的正确方法。

Any help is appreciated. 任何帮助表示赞赏。

Update: Note that this old but excellent answer is still a very good outline for how to approach solving this problem, at least as along the evolutionary scale as Win7 and IE11. 更新:请注意,这个古老而出色的答案仍然是如何解决该问题的一个很好的大纲,至少在Win7和IE11的进化规模上如此。 I just succeeded making it all work using the Answerer's Firebreath.org toolset as a jumping off point. 我只是使用Answerer的Firebreath.org工具集成功地使所有这些工作成为了起点。 It's not simple but it can be done. 这并不简单,但是可以做到。 I've added a reference to that project to the reference list below since it may make a more logical jumping off point for current developers than this overview is. 我已将该项目的引用添加到下面的引用列表中,因为与当前概述相比,它可能为当前开发人员提供更合乎逻辑的起点。


Hooray - I have just finished an identical project, so you'll be pleased to know that it's actually possible. Hooray-我刚刚完成了一个相同的项目,所以您将很高兴知道它实际上是可能的。 I have only tested this on XP - I understand there may be issues where Vista/7 don't allow msiexec to be called. 我仅在XP上进行了测试-我了解在Vista / 7不允许调用msiexec可能会出现问题。

Given that you have an assembly correctly exposing a COM interface, I did the following: 鉴于您有正确公开COM接口的程序集,我执行了以下操作:

  • Strong-named the assembly. 强名大会。
  • Created an INF file 创建一个INF文件
  • Created an MSI using the Visual Studio 2008 "Setup Project" template. 使用Visual Studio 2008“安装项目”模板创建了一个MSI。
  • Created a CAB file using "iexpress.exe" bundled with Windows XP. 使用Windows XP附带的“ iexpress.exe”创建了一个CAB文件。

Create INF file 创建INF文件

The *.inf file I used looks like: 我使用的* .inf文件如下所示:

[version]
signature="$CHICAGO$"
AdvancedINF=2.0

[Setup Hooks]
install=install

[install]
run=msiexec.exe /package """%EXTRACT_DIR%\SampInst.msi""" /qn

The only bit you should need to change is the SampInst.msi . 您需要更改的唯一位是SampInst.msi Note I would use an 8.3 filename, as long filenames can cause issues. 注意我将使用8.3文件名,因为长文件名可能会导致问题。 While testing, I would not use the qn switch either, as that is a silent install. 在测试时,我也不会使用qn开关,因为这是无提示安装。

Create the Installer 创建安装程序

The installer has to do only one thing, and that is register the assembly by calling RegAsm on it. 安装程序只需要做一件事,那就是通过在其上调用RegAsm来注册程序集。 Most installers will provide some method to easily do this. 大多数安装程序会提供一些方法来轻松执行此操作。 For example, an installer created through VS 2008 will simply need to have the “Register” property of the assembly set to “vsdrpCOM”. 例如,通过VS 2008创建的安装程序仅需要将程序集的“ Register”属性设置为“ vsdrpCOM”。 Note that vsdrpCOM should be chosen as it generates the appropriate registry entries at build-time. 请注意,应该选择vsdrpCOM,因为它会在构建时生成适当的注册表项。 The vsdrpCOMSelfRegistration setting is likely to fail as it calls RegAsm at run-time, and will thus not work for non-administrators. vsdrpCOMSelfRegistration设置可能会失败,因为它会在运行时调用RegAsm,因此不适用于非管理员。

Package the installer into a CAB file 将安装程序打包到一个CAB文件中

This can be done by any cab archiver. 可以由任何出租车存档器完成。 Windows XP contains iexpress.exe, a wizard driven archiver, while Microsoft's CAB SDK contains cabarc.exe. Windows XP包含向导驱动的存档器iexpress.exe,而Microsoft的CAB SDK包含cabarc.exe。 Other 3rd-party tools are also available. 也可以使用其他第三方工具。 Note that you will need to reserve space in the CAB file for code-signing if you are going to sign the CAB. 请注意,如果要对CAB进行签名,则需要在CAB文件中保留空间以进行代码签名。

You will need to CAB the INF file, and the MSI file. 您将需要CAB INF文件和MSI文件。 You will not need to CAB the Setup.Exe file. 您将不需要CAB Setup.Exe文件。

Handy hint: The VS2008 Setup Project project type allows you to set a post-build step in the properties, so you can build and CAB in a single step. 方便的提示:VS2008 Setup Project项目类型允许您在属性中设置构建后步骤,因此您可以在一个步骤中进行构建和CAB。 My post-build step looks like: 我的构建后步骤如下所示:

cd "$(ProjectDir)"
"%WINDIR%\System32\Makecab.exe" /f "VboCslib.ddf"

The DDF file format is documented . 记录 DDF文件格式。

Sample HTML page 示例HTML页面

The object tag is used to point to the cab file containing the installer. object标签用于指向包含安装程序的cab文件。 A very simple HTML page which would deploy an ActiveXControl would be: 部署ActiveXControl的一个非常简单的HTML页面是:

<html>
<head></head>
<body>

    <!--
        ID :    The id of the ActiveX control to be used in JavaScript.
        CLASSID : The GUID associated with the ActiveX control.
        CODEBASE: The location containing the CAB installer for the ActiveX 
       control. This could be a URL, or a relative path.
        -->
    <OBJECT ID="MyActiveXControl"
            CLASSID="CLSID:FC36FAE1-48E0-4f6b-B469-E1B5A8C6D1AC"
            CODEBASE="cabfiles\SampleCabFile.CAB#version=1,0,0,0">
        </OBJECT>

        <script>
            MyActiveXControl.SomeMethod();
        </script>
    </body>
    </html>

Handy hints 方便的提示

  • Ensure your installer installs on a "per-user" basis, not a "per-machine" basis. 确保您的安装程序是按“每用户”安装的,而不是“按机器”安装的。 This will make it more likely to install if the user does not have admin privileges. 如果用户没有管理员权限,这将使其更有可能安装。

Trouble-shooting 故障排除

Internet Explorer 6 actually provides a really useful diagnostic aid. Internet Explorer 6实际上提供了非常有用的诊断工具。 Clear your Temporary Internet Files, then navigate to the web-page. 清除您的Internet临时文件,然后导航到该网页。 If the installation does not work, go to your temporary internet files and you will see a couple of files in there. 如果安装不起作用,请转到您的临时Internet文件,您将在其中看到几个文件。 One of these will be an error log starting ?CodeDownloadErrorLog. 其中之一将是启动?CodeDownloadErrorLog的错误日志。 Drag it to your desktop and open it in notepad, and it will give details on what it was trying to do when it failed. 将其拖到桌面上并在记事本中打开,它将提供有关失败时尝试执行的操作的详细信息。

References 参考文献

  1. Microsoft KB247257 – Steps for signing a .cab file Microsoft KB247257 –签署.cab文件的步骤
  2. MSDN – About INF File Architecture MSDN –关于INF文件架构
  3. SN.EXE - Code Strong Programs with Strong Names SN.EXE-使用强名称编码强程序
  4. Nikolkos Craft – How To: Deploy .NET ActiveX Control Nikolkos Craft –如何:部署.NET ActiveX控件
  5. CodeProject – Create ActiveX .NET Step by Step CodeProject –分步创建ActiveX .NET
  6. CodeProject – Downloading C# ActiveX Components through CAB file CodeProject –通过CAB文件下载C#ActiveX组件
  7. MSDN - ALLUSERS Property (Windows) MSDN -ALLUSERS属性(Windows)
  8. MSDN – Non-Admin ActiveX Controls MSDN –非管理员ActiveX控件
  9. MSDN – Microsoft Cabinet Format MSDN – Microsoft内阁格式

Update: Firebreath.org has a toolset for generating browser plugins for many platforms. 更新: Firebreath.org具有用于为许多平台生成浏览器插件的工具集。 The IE/ActiveX code to solve the problem posed here is just a subset. 解决此处提出的问题的IE / ActiveX代码只是其中的一个子集。 But as of 6 Nov 2014, I found it easier to start with Firebreath and its instructions than to try to build up my dev environment and roll all my own solutions from scratch. 但是截至2014年11月6日,我发现开始尝试Firebreath及其说明要比尝试建立我的开发环境并从头开始构建自己的所有解决方案容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM