使用 WiX 安装时启动外部服务

Starting an external service on install with WiX

我有一项服务(安装和工作没有问题),但需要 "Smart Card" 服务在安装时 运行 才能正常运行。有没有办法配置 WiX 安装程序(通过 BURN 引导程序或主 MSI)以在安装时启动此服务(如果不是 运行?

我试过使用服务控件元素,但我担心 "Remove" 属性会导致智能卡服务在应用程序被卸载时被卸载!

我不清楚简单地删除此属性是否可以解决问题并且不会在卸载时删除服务。我只想启动服务,如果它不是 运行 并在卸载时保留它 运行。

<Component Id="SmartCardServiceStarter" Directory="INSTALLFOLDER" 
           Guid="A-GUID" KeyPath="yes">
  <ServiceControl Id="SmartCardServiceStarter"
                    Start="install"
                    Stop="uninstall"
                    Remove="???"
                    Name="SCardSvr"
                    Wait="yes" />
  <Condition><![CDATA[STARTSERVICEONINSTALL <> "false"]]></Condition>
</Component>

可选属性:您可以省略 Remove attribute,并且您还可以将服务设置为仅在安装时停止和启动,即使您卸载了服务 运行ning(这可能很好,因为您不知道其他应用程序是否依赖于该服务 - 您可能会喜欢并检测您最初是否必须启动该服务,但这可能不是必需的):

<Component Id="SmartCardServiceStarter" Directory="INSTALLFOLDER" Guid="PUT-GUID-HERE" KeyPath="yes">
  <ServiceControl Id="SmartCardServiceStarter"
                    Start="install"
                    Stop="install"
                    Name="SCardSvr"
                    Wait="yes" />
  <!-- <Condition><![CDATA[STARTSERVICEONINSTALL <> "false"]]></Condition> -->
</Component>

ServiceControl Table: You can witness the result of the different combinations of attributes in the ServiceControl element (WiX source) by viewing your compiled MSI with (towards bottom, prefer Orca over SuperOrca, I have seen the latter persist changes unexpectedly) and inspecting the ServiceControl Table(完成 MSI)。更改将显示在 "Event" column 中。根据 MSI SDK 文档匹配位标志值。

Built-In System Service: 鉴于这是一个系统服务,我想你可以设置它只启动然后离开它打开,根本不添加任何停止,但您可能需要它停止以在重大升级期间替换您自己的文件?我不知道情节。请彻底测试 - 并为这样的东西使用虚拟。很明显,我知道。主要升级方案可能会指示您希望停止安装,以获取更新并防止锁定要替换的文件。

条件:您应该能够使用该条件来控制是否希望服务操作 运行 或不是。实际上,条件控制是否安装承载这些服务操作的组件,从而确定服务操作是否 运行(以及)。