4
votes

I have a windows service installed with a MSI installer. I'm trying to get this installer to act as an "updater" also by first having it uninstall itself (RemovePreviousVersions=true ?) and then reinstalling itself. The way i understand it is that with RemovePreviousVersions=true, when the installer runs the second time it should notice that the current version of the product is different then the installed version and it would perform the Uninstall action on the installed product, then perform the Install action on the new version. This however does not seem to be the case. It appears that the initial uninstall step never happens and the installer just tries to perform an install. This is causing me issues because the installer custom actions are a service install and, of course, the service is already installed and then complains with "The service already exists".

How do i get a windows installer to first uninstall and then install a service? Perhaps i'm wrong in my understanding of how MSI installers work? Is there a better way to install a service?

2

2 Answers

5
votes

Here is how I do it.

Set up an Upgrade Id GUID (must remain the same across installs):

<?define ProductVersion="3.0.43.0" ?>
<?define UpgradeCode="{3F198E84-0BB6-4765-B48A-64DE5F8C4A65}" ?>

<Product Id='*' Name='...' Language='1033'
         Version='$(var.ProductVersion)' Manufacturer='...'
         UpgradeCode='$(var.UpgradeCode)'>


<Property Id='PREVIOUSVERSIONSINSTALLED' Secure='yes'/>
<Upgrade Id='$(var.UpgradeCode)'>
  <UpgradeVersion Minimum='1.0.0.0'
                  Maximum='$(var.ProductVersion)'
                  IncludeMinimum='yes'
                  IncludeMaximum='no'
                  Property='PREVIOUSVERSIONSINSTALLED'/>
</Upgrade>

Then inside the server Component tag:

<ServiceInstall Id='server.exe' Name='...' DisplayName='...' Type='ownProcess'
                Interactive='no' Start='auto' Vital='yes' ErrorControl='normal'
                Account='LocalSystem'
</ServiceInstall>
<ServiceControl Id='server_start' Name='...' Start='install' Wait='yes' />
<ServiceControl Id='server_stop' Name='...' Stop='both' Wait='yes' />
<ServiceControl Id='server_remove' Name='...' Remove='uninstall' Wait='yes' />

This stops the running service, removes it, installs the new service and starts it again.

And finally:

<InstallExecuteSequence>
  <LaunchConditions After='AppSearch' />
  <RemoveExistingProducts After='InstallInitialize' />
</InstallExecuteSequence>
0
votes

Where do you have RemoveExistingProducts scheduled in your execute sequence? Behavior varies based on this. See the description of the action - http://msdn.microsoft.com/en-us/library/aa371197%28v=vs.85%29.aspx