0

I'm working on a Wix installer which should install multiple Services based on the same runner. This a some dlls which will be loaded by the runner. With sc.exe this works fine on my test system. Now my question, can I use standard Wix ServiceInstall for this? I have only one runner.exe and I'm not sure how to write this in the XML. Or would a Custom Action be the right way?

Thanks!!

AndyO
  • 19
  • 2
  • A custom action shouldn't be needed. WiX should handle this. I can't give a detailed answer without more understanding of your situation. – Christopher Painter Mar 19 '20 at 02:10
  • The problem that I see, is that I can use the ServiceInstall Tag only after a file. So I can with one Runner.exe only install one Service. Or I'm wrong with this? – AndyO Mar 19 '20 at 06:32

1 Answers1

0

The ServiceInstall and ServiceControl elements don't come after the file element per say but they are children on the Component element. They target the keypath of the component which happens to be the File element. You can easily have multiple services defined in a single component pointing to the same executable.

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

To have each service behave differently you'll have to write code in your service to access ServiceBase.ServiceName (this.ServiceName in the OnStart method likely). From here you can dynamically load different classes from different assemblies.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100