How to only stop and not uninstall windows services when major upgrade in wix?
Asked Answered
F

2

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!

Footboard answered 12/4, 2013 at 7:29 Comment(1)
Similar thread: #22117638Chadwell
Y
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.

Yunyunfei answered 13/4, 2013 at 3:45 Comment(3)
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.Chadwell
It doesn't work for me. It is still uninstalling the service and reinstalling it.Blare
Is this the recommended/best way or is there any best alternative for this question @Ron MenschingPalazzo
C
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.

Cozen answered 15/8, 2019 at 23:10 Comment(2)
This worked for me! These two answers also are helpful in understanding why this works: https://mcmap.net/q/104510/-how-to-add-a-wix-custom-action-that-happens-only-on-uninstall-via-msi and https://mcmap.net/q/104510/-how-to-add-a-wix-custom-action-that-happens-only-on-uninstall-via-msiReclinate
If the user changes the installation path during the major upgrade, won't the services be orphaned?Misanthrope

© 2022 - 2024 — McMap. All rights reserved.