3

I have a service (which is installing and working no problem), but requires the "Smart Card" service to be running on install for it to function correctly. Is there a way to configure WiX installer (through the BURN bootstrapper or the main MSI) to start this service on install if it isnt running?

I have tried using a service control element, but I am concerned that the "Remove" attribute will cause the SmartCard service to be uninstalled when the application is!

It is unclear to me whether simply removing this attribute would solve the issue and wouldn't remove the service on uninstall. I only want to start the service if it's not running and leave it running on uninstall.

<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>
Chris Watts
  • 822
  • 1
  • 9
  • 27

1 Answers1

2

Optional Attributes: You can leave out the Remove attribute, and you can also set the service to stop and start on install only, leaving the service running even if you uninstall (which might be good since you can't know if other applications depend on the service - you could go fancy and detect if you originally had to start the service, but that is probably not necessary):

<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 Orca or an equivalent tool (towards bottom, prefer Orca over SuperOrca, I have seen the latter persist changes unexpectedly) and inspecting the ServiceControl Table (finished MSI). The changes will show in the "Event" column. Match bit-flag values according to the MSI SDK documentation.

Built-In System Service: Seeing as this is a system service, I suppose you could set it to start only and leave it on, not adding any stop at all, but you might need it to stop to replace your own files during major upgrades? I don't know the scenario. Please test thoroughly - and use a virtual for stuff like this. Obvious, I know. Major upgrade scenarios would probably dictate that you want a stop on install, to get your updates in and to prevent locks on your files that you want to replace.

Condition: You should be able to use that condition to control whether you want the service actions to run or not. Actually the condition controls whether the component hosting those service actions will be installed or not, hence determining if the service actions will run or not (as well).

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • They are optional?!?!?! why doesnt the documentation say so on the WiX website! I had wondered if that was the case, but without explicit say so, I didnt want to try and end up removing a service! I shall try this out – Chris Watts Mar 28 '19 at 13:56
  • True, I suppose they should update the web-site at least, or maybe a sample would help? Either way, as MSI-specialists this is actually clear, but for non-MSI specialists it does come as a huge surprise I guess. MSI really has [a lot of quirks](https://stackoverflow.com/questions/45840086/how-do-i-avoid-common-design-flaws-in-my-wix-msi-deployment-solution) (very messy, ad-hoc "notes"), and some [crucial corporate benefits](https://stackoverflow.com/a/49632260/129130). – Stein Åsmul Mar 28 '19 at 13:58
  • Worked a treat! Thanks for getting me out of a bind! – Chris Watts Mar 28 '19 at 15:45
  • Great, glad it worked. Please test thoroughly, MSI is complex. – Stein Åsmul Mar 28 '19 at 15:47
  • agreed, just have to set the service to automatic start now, from manual... yay msi complexities! – Chris Watts Mar 28 '19 at 15:49
  • Oh, yes. That is true. I have never done that for system services, but it should be fine I think. You might make a note of that in your documentation if you have that for your setup. For auditing teams and security teams. They want to know what is running and why. I usually do a 1 page PDF called **`"large scale deployment.pdf"`** with hints on how to deploy and things to be aware of. No sample to show you right now. Could your application start the service instead? (privileges?) – Stein Åsmul Mar 28 '19 at 15:52
  • I have added a service dependency while doing this work, but i shall play around using the ServiceInstall configuration, might be possible to set it to auto using that without interfering with it during uninstall – Chris Watts Mar 28 '19 at 16:00
  • In fact, see here: https://stackoverflow.com/questions/47630422/set-service-startup-type-in-wix-installer its not possible, only through registry. – Chris Watts Mar 28 '19 at 16:05
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/190857/discussion-between-stein-asmul-and-chris-watts). – Stein Åsmul Mar 28 '19 at 16:11