5

I'm working on an installer that is supposed to install Windows services in wix v3.8. The problem is that we need to make a major upgrade without uninstalling the service only to stop it.

We're using ServiceInstall and ServiceControl inside the component that holds the service exe file. Is there a way to make the execution of ServiceInstall conditional (using a condition like REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE) so the service is not uninstalled when upgrading (just stopped so we can upgrade the files)?

One solution would be to use custom actions, but maybe there is a better way?

Thanks!

zhoulin Wang
  • 559
  • 2
  • 5
  • 19
  • Similar thread: http://stackoverflow.com/questions/22117138/prevent-service-removal-install-during-wix-major-upgrade-service-not-stopping – Stein Åsmul May 08 '14 at 16:51

2 Answers2

9

You would have to override the action that process those elements. The following may work as long as you are okay if it applies to all services in your MSI package (if you only have one service then good on ya):

<InstallExecuteSequence>
   <DeleteServices>NOT UPGRADINGPRODUCTCODE</DeleteServices>
</InstallExecuteSequence>

You don't need to condition for remove since the DeleteServices would already factor in the state of the Component.

Rob Mensching
  • 33,834
  • 5
  • 90
  • 130
  • What happens if a service is being deleted during the major upgrade? Perhaps a new one is added, and the old one deleted? I don't see how this would delete the actual service registration - but the files might be removed? Messing with standard actions is always scary, but this deployment scenario should probably be designed and accounted for - seems very normal. Probably the most intended upgrade behavior for upgrade installations to not recreate the service registration. – Stein Åsmul Mar 01 '14 at 20:02
  • 1
    It doesn't work for me. It is still uninstalling the service and reinstalling it. – Ven Nov 16 '17 at 12:21
  • Is this the recommended/best way or is there any best alternative for this question @Ron Mensching – user3664223 Jan 25 '20 at 19:26
2

What finally ended up working for me was

  <DeleteServices><![CDATA[REMOVE ~= "ALL" AND (NOT UPGRADINGPRODUCTCODE)]]> </DeleteServices>
  <InstallServices><![CDATA[NOT Installed]]> </InstallServices>

I arrived at this answer through a series of trial and error attempts and a combination of a few other threads with similar answers.

One of the possible reasons why only the doesn't work is because WIX also removes the service upon re-install.. we only want to install the service once, during the initial install. We also want to make sure that the service is removed upon uninstall. This is the only combination of conditions which worked for me, allowing the service to keep its settings and user account.

Vikram S.
  • 31
  • 1
  • 1
  • This worked for me! These two answers also are helpful in understanding why this works: https://stackoverflow.com/a/17608049/670028 and https://stackoverflow.com/a/321874/670028 – Randy Burden Mar 17 '21 at 18:35
  • If the user changes the installation path during the major upgrade, won't the services be orphaned? – DaveWilliamson Jan 04 '22 at 21:52