You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Windows Installer XML在.msm文件中创建Class表与ProgId表

Wix实现Class与ProgId表的完整示例

当你在<File>节点下配置Class和ProgId仅生成注册表条目时,说明需要显式定义Class、ProgId相关的Wix元素来对应MSI中的Class表和ProgId表,而非仅依赖文件的注册表关联。以下是完整的Wix .msm模块实现示例:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Module Id="MyCustomModule" Language="1033" Version="1.0.0.0">
    <Package Id="*" Manufacturer="MyCompany" InstallerVersion="200" />

    <!-- 组件组,包含Class、ProgId及关联文件 -->
    <ComponentGroup Id="MyComponentGroup">
      <Component Id="MyComComponent" Guid="PUT-COMPONENT-GUID-HERE" Directory="INSTALLFOLDER">
        <!-- 要注册的COM文件 -->
        <File Id="MyComDll" Source="path/to/your/com.dll" KeyPath="yes">
          <!-- 定义Class表条目 -->
          <Class Id="PUT-CLASS-GUID-HERE" Context="InprocServer32" Description="My COM Class" ThreadingModel="Both" ForeignServer="mscoree.dll">
            <!-- 关联ProgId表条目 -->
            <ProgId Id="MyApp.MyClass" Description="My COM Class ProgId">
              <!-- ProgId与Class的版本关联 -->
              <Version Class="PUT-CLASS-GUID-HERE" Version="1.0" />
            </ProgId>
          </Class>
        </File>

        <!-- 可选:补充ProgId到CLSID的映射注册表项 -->
        <RegistryValue Root="HKCR" Key="MyApp.MyClass\CLSID" Value="[PUT-CLASS-GUID-HERE]" Type="string" Action="write" />
      </Component>
    </ComponentGroup>

    <!-- 模块依赖声明,供主安装包引用时使用 -->
    <ModuleDependency Id="CoreDependency" />
  </Module>
</Wix>

关键元素说明

  • <Class>:直接映射到MSI的Class表,Id为COM类的唯一GUID,Context指定服务器类型(InprocServer32用于进程内组件,LocalServer32用于进程外组件),ThreadingModel设置COM线程模型(如Both、Apartment)。
  • <ProgId>:对应MSI的ProgId表,Id为对外暴露的程序标识符,通过<Version>子元素绑定到对应的Class GUID。
  • ForeignServer:若为.NET COM互操作组件,需指定mscoree.dll作为宿主服务器;原生COM组件可省略该属性,默认使用当前文件路径。
  • GUID替换:将示例中的PUT-COMPONENT-GUID-HERE和PUT-CLASS-GUID-HERE替换为实际生成的GUID(可通过uuidgen.exe工具生成)。

编译与验证步骤

  1. 使用candle编译WXS文件:
    candle MyModule.wxs -out MyModule.wixobj
    
  2. 使用light生成.msm模块文件:
    light MyModule.wixobj -out MyModule.msm
    
  3. 用Orca工具打开生成的.msm,检查Class表和ProgId表是否已生成预期条目。

内容的提问来源于stack exchange,提问作者KaczA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 12:35:26