首页 > 解决方案 > WIX:使用运行器和多 dll 安装服务

问题描述

我正在开发一个 Wix 安装程序,它应该基于同一个运行器安装多个服务。这是一些将由跑步者加载的 dll。使用 sc.exe,这在我的测试系统上运行良好。现在我的问题是,我可以为此使用标准的 Wix ServiceInstall 吗?我只有一个 runner.exe,我不确定如何在 XML 中编写它。还是自定义操作是正确的方式?

谢谢!!

标签: servicewixsc.exe

解决方案


ServiceInstall 和 ServiceControl 元素不会出现文件元素之后,但它们是 Component 元素上的子元素。它们针对恰好是 File 元素的组件的键路径。您可以轻松地将多个服务定义在指向同一个可执行文件的单个组件中。

<Component Id="c1" Guid="dbc1b8dd-14e1-380f-5793-4a746fa0c5c5">
      <File Id="f1" Source="$(var.SourceDir)\TestService.exe" KeyPath="yes" />
      <ServiceInstall Id="si1" Name="TestService1" DisplayName="TestService1 Service" Description="TestService1 Service" ErrorControl="normal" Start="auto" Type="ownProcess" />
      <ServiceControl Id="sc1" Name="TestService1" Start="install" Stop="both" Remove="both" Wait="yes" />
      <ServiceInstall Id="si2" Name="TestService2" DisplayName="TestService2 Service" Description="TestService Service" ErrorControl="normal" Start="auto" Type="ownProcess" />
      <ServiceControl Id="sc2" Name="TestService2" Start="install" Stop="both" Remove="both" Wait="yes" />
    </Component>

要让每个服务表现不同,您必须在服务中编写代码来访问 ServiceBase.ServiceName(可能是 OnStart 方法中的 this.ServiceName)。从这里您可以从不同的程序集中动态加载不同的类。


推荐阅读