Question

I'm writing a MSI which installs a windows service and adds some DLLs which the service uses. Those DLLs are features which can be added or removed using the installer.

After a user modifies the installed product(eq. add a new feature), windows service needs to be restarted. Is there a more elegant way of doing so in WiX 3.5 other than calling a custom action which would restart the service?

This is how I'm starting the service.

<ServiceControl Id="StartService" Name="MyService" Start="install" Stop="both" Remove="uninstall"  Wait="yes" />

EDIT: Here's the complete component code. Disregard the ids.

<Component Id="MyService" Guid="GUID">
     <File Id="MyService"
      Source="$(var.BuildDestination)/$(var.NameSpacePrefix).MyService.exe"
      KeyPath="yes"
      >
</File>
<RemoveFile Id='AppConfigFile' On='uninstall' Name='MyService.exe.Config' />
<User xmlns="http://schemas.microsoft.com/wix/UtilExtension"
         Id="ServiceAccount"
         CreateUser="no"
         FailIfExists="no"
         RemoveOnUninstall="no"
         UpdateIfExists="yes"
         Disabled="no"
         LogonAsService="yes"
         Name="[ACCOUNT]"
         Password="[PASSWORD]" />
<ServiceInstall
          Id="MyService"
          Type="ownProcess"
          Vital="yes"
          Name="MyService"
          DisplayName="MyService"
          Description="MyService"
          Start="auto"
          Account="[ACCOUNT]"
          Password="[PASSWORD]"
          ErrorControl="ignore"
          Interactive="no">
</ServiceInstall>
<ServiceControl Id="StartService"
                Name="MyService"
                Start="install"
                Stop="both"
                Remove="both"
                Wait="yes"
                >
</ServiceControl>

Was it helpful?

Solution

As the state of the service feature(feature which installs and starts the service) wasn't updated, the service itself wasn't stopped and started too. I've solved the issue by adding ServiceControl to all components which are separate features.

<Component Id="Modules1" Guid="GUID">
<File Id="Modules.1" Source="$(var.BuildDestination)/$(var.NameSpacePrefix)Modules.1.dll" KeyPath="yes">
</File>
<ServiceControl Id="StartService1"
               Name="MyService"
               Start="install"
               Stop="both"
               Wait="yes"
                >
</ServiceControl>

OTHER TIPS

This solution works for me:

<Component Directory="APPLICATIONFOLDER">
    <File           Source      ="MyService.exe"
                    KeyPath     ="yes" />
    <ServiceInstall Id          ="MyService.exe"
                    Name        ="My Service"
                    Account     ="LocalSystem"
                    Start       ="auto"
                    ErrorControl="normal"
                    Interactive ="no"
                    Type        ="ownProcess"
                    Description ="My service does stuff."/>
    <ServiceControl Id          ="MyService.exe"
                    Name        ="My Service"
                    Start       ="install"
                    Stop        ="both"
                    Remove      ="both"
                    Wait        ="no"/>
</Component>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top