I'm working on an installer that is supposed to install several Windows services. We make new builds (with new .msi files) pretty often, and we use major upgrades to make it easy to install over a previous installation.
The problem is that we need to update the service files without overwriting the service configuration (account username and password, for instance).
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!
It seems I was looking in the wrong place. The solution to my problem is to add the NOT UPGRADINGPRODUCTCODE
to the DeleteServices
standard action.
This fixes my problem. The caveat of this approach is that all services installed by the current msi
file are deleted (or not). So I can't delete/keep services selectively on an upgrade. This is fine with me, however - my requirement of keeping the service logon information (but not the actual service code) across upgrades is fulfilled.
UPDATE: The condition for DeleteServices
is accessible from WiX in the InstallExecuteSequence
element.
This is how the solution should look:
<DeleteServices><![CDATA[NOT UPGRADINGPRODUCTCODE]]></DeleteServices>
Add this under the InstallExecuteSequence tag.
Note: Make sure the original first version MSI has this tag or else you will have to uninstall and install completely and only then this configuration will take effect on upgrades.
Note2: you don't have to use the CDATA tag it can also look like this:
<DeleteServices>NOT UPGRADINGPRODUCTCODE</DeleteServices>
WiX will only update components if their version is newer. It only checks one of the fields (File version of assembly version, I can't remember) so you can keep current version info in one and keep it static in the other. This might be a hack that works for you...
I created 2 component for the same exe with one condition each. One for WIX_UPGRADE_DETECTED and one for NOT WIX_UPGRADE_DETECTED. In the WIX_UPGRADE_DETECTED, I would not include the serviceinstall element, and the NOT WIX_UPGRADE_DETECTED, include the serviceinstall element.
Using conditions on the service standard actions won't scale past one service.
The way to go about this is to schedule RemoveExistingProducts before InstallFinalize. Then make sure that your newer build has a service EXE with the same version as what it's replacing. This way Windows Installer won't uninstall/reinstall that component.
Finally put your configuration data in another component that will get installed and code your service to notice the data has configuration has changed and reload it if needed.
Personally I don't do this. I stop, reinstall, start services all the time with no horrible consequence other then the install takes a few seconds longer.