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

发布于 2024-10-27 22:10:34 字数 487 浏览 4 评论 0原文

我正在拼命尝试部署一个用 C# 开发的 IE 的 ActiveX 作为 CAB 存档。我阅读了很多资源(其中一些来自 StackOverflow),似乎很多人都遇到了同样的问题。我尝试了 3 种解决方案:a) 创建 CAB VS 项目,b) 使用 CABARC 手动创建 CAB,并在 INF 中进行 COM 注册,c) 通过启动 msiexec.他们都没有工作。我什至尝试过 d) 创建一个启动 msiexec 的引导程序,但没有成功(因为有些人建议在 Vista 上简单地启动 msiexec 是行不通的)。

我运行的是 Windows Vista,但我的项目即使在 XP 上的 IE6 上也无法运行。

当我使用 MSI 安装 ActiveX 时,在所有 Windows 上一切正常。显然 CAB 的东西不起作用,我还找不到调试整个过程的正确方法。

任何帮助表示赞赏。

I am desperately trying to deploy an ActiveX for IE developed in C# as a CAB archive. I have read many resources (some of them from StackOverflow) and it appears a lot of people are having the same problems. 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. 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).

I am running Windows Vista but my project fails to run even on IE6 on XP.

When I install ActiveX using MSI, all is fine on ALL Windows. Apparently CAB thing is not working and I could not find a proper way to debug this whole process yet.

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白龙吟 2024-11-03 22:10:34

更新:请注意,这个古老但优秀的答案仍然是如何解决此问题的一个非常好的概述,至少沿着 Win7 和 IE11 的进化规模。我刚刚使用 Answerer 的 Firebreath.org 工具集作为起点,成功地使这一切正常工作。这并不简单,但可以做到。我已将对该项目的引用添加到下面的参考列表中,因为它可能为当前开发人员提供比此概述更合乎逻辑的起点。


万岁 - 我刚刚完成了一个相同的项目,所以您将很高兴知道这实际上是可能的。我只在 XP 上对此进行了测试 - 我知道 Vista/7 可能存在不允许调用 msiexec 的问题。

鉴于您有一个正确公开 COM 接口的程序集,我执行了以下操作:

  • 对程序集进行强命名。
  • 创建了 INF 文件
  • 使用 Visual Studio 2008“安装项目”模板创建了 MSI。
  • 使用与 Windows XP 捆绑在一起的“iexpress.exe”创建了一个 CAB 文件。

创建 INF 文件

我使用的 *.inf 文件如下所示:

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

[Setup Hooks]
install=install

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

您唯一需要更改的部分是 SampInst.msi。注意我会使用 8.3 文件名,因为长文件名可能会导致问题。在测试时,我也不会使用 qn 开关,因为这是静默安装。

创建安装程序

安装程序只需执行一件事,那就是通过调用 RegAsm 来注册程序集。大多数安装程序都会提供一些方法来轻松完成此操作。例如,通过 VS 2008 创建的安装程序只需将程序集的“Register”属性设置为“vsdrpCOM”。请注意,应选择 vsdrpCOM,因为它会在构建时生成适当的注册表项。 vsdrpCOMSelfRegistration 设置可能会失败,因为它在运行时调用 RegAsm,因此不适用于非管理员。

将安装程序打包到 CAB 文件中

这可以通过任何 cab 归档程序来完成。 Windows XP 包含 iexpress.exe,一个向导驱动的归档程序,而 Microsoft 的 CAB SDK 包含 cabarc.exe。其他第三方工具也可用。
请注意,如果要签署 CAB,则需要在 CAB 文件中预留空间用于代码签名。

您将需要 CAB INF 文件和 MSI 文件。您不需要 CAB Setup.Exe 文件。

方便的提示:VS2008 安装项目项目类型允许您在属性中设置构建后步骤,这样您就可以在一个步骤中构建和 CAB。我的构建后步骤如下所示:

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

DDF 文件格式已记录

HTML 页面示例

对象标记用于指向包含安装程序的 cab 文件。部署 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>

方便的提示

  • 确保您的安装程序基于“每用户”安装,而不是“每台计算机”安装。如果用户没有管理员权限,这将使其更有可能安装。

故障排除

Internet Explorer 6 实际上提供了非常有用的诊断帮助。清除您的临时 Internet 文件,然后导航到该网页。如果安装不起作用,请转到临时 Internet 文件,您将在其中看到几个文件。其中之一是以 ?CodeDownloadErrorLog 开头的错误日志。将其拖到桌面并在记事本中打开它,它将提供有关失败时尝试执行的操作的详细信息。

参考

  1. Microsoft KB247257 – 签署 .cab 文件的步骤
  2. MSDN – 关于INF 文件体系结构
  3. SN.EXE - 使用强名称编写强程序
  4. Nikolkos 工艺 – 如何:部署 .NET ActiveX 控件
  5. CodeProject – 创建 ActiveX .NET步骤
  6. CodeProject – 通过 CAB 文件下载 C# ActiveX 组件
  7. MSDN - ALLUSERS 属性 (Windows)
  8. MSDN – 非管理员 ActiveX 控件
  9. MSDN< /a> – Microsoft Cabinet 格式

更新:Firebreath.org 拥有用于为许多平台生成浏览器插件的工具集。解决这里提出的问题的 IE/ActiveX 代码只是一个子集。但截至 2014 年 11 月 6 日,我发现开始使用 Firebreath 及其说明比尝试构建我的开发环境并从头开始推出我自己的所有解决方案更容易。

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. I just succeeded making it all work using the Answerer's Firebreath.org toolset as a jumping off point. 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. I have only tested this on XP - I understand there may be issues where Vista/7 don't allow msiexec to be called.

Given that you have an assembly correctly exposing a COM interface, I did the following:

  • Strong-named the assembly.
  • Created an INF file
  • Created an MSI using the Visual Studio 2008 "Setup Project" template.
  • Created a CAB file using "iexpress.exe" bundled with Windows XP.

Create INF file

The *.inf file I used looks like:

[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. Note I would use an 8.3 filename, as long filenames can cause issues. While testing, I would not use the qn switch either, as that is a silent install.

Create the Installer

The installer has to do only one thing, and that is register the assembly by calling RegAsm on it. 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”. Note that vsdrpCOM should be chosen as it generates the appropriate registry entries at build-time. The vsdrpCOMSelfRegistration setting is likely to fail as it calls RegAsm at run-time, and will thus not work for non-administrators.

Package the installer into a CAB file

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. 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.

You will need to CAB the INF file, and the MSI file. You will not need to CAB the Setup.Exe file.

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. My post-build step looks like:

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

The DDF file format is documented.

Sample HTML page

The object tag is used to point to the cab file containing the installer. A very simple HTML page which would deploy an ActiveXControl would be:

<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. Clear your Temporary Internet Files, then navigate to the web-page. If the installation does not work, go to your temporary internet files and you will see a couple of files in there. One of these will be an error log starting ?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
  2. MSDN – About INF File Architecture
  3. SN.EXE - Code Strong Programs with Strong Names
  4. Nikolkos Craft – How To: Deploy .NET ActiveX Control
  5. CodeProject – Create ActiveX .NET Step by Step
  6. CodeProject – Downloading C# ActiveX Components through CAB file
  7. MSDN - ALLUSERS Property (Windows)
  8. MSDN – Non-Admin ActiveX Controls
  9. MSDN – Microsoft Cabinet Format

Update: Firebreath.org has a toolset for generating browser plugins for many platforms. The IE/ActiveX code to solve the problem posed here is just a subset. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文