8
votes

I am trying to create a WiX MSI installer for my Windows service that will install the service, but not start it. I can't seem to find anywhere that explains how to do this or if it's possible.

I tried to remove the ServiceControl I had for starting the service as well as toggling the Start attribute on the ServiceInstall without any luck. It has to be possible to do this, right? I just want the MSI file to install the service and let the user start it when they want.

<Component Id="ServiceInstaller" Guid="9e578e3d-0339-425c-8633-f54ffaaa4921">

    <ServiceInstall Id="ReportingServiceInstaller"
                    Type="ownProcess"
                    Vital="yes"
                    Name="WindowsService.exe"
                    DisplayName="WindowsService"
                    Description="Wickedly awesome and amazing service."
                    ErrorControl="ignore"
                    Account="NT AUTHORITY\LocalService"
                    Start="auto"
                    Interactive="no" />

    <ServiceControl Id="ServiceControl_Stop"
                    Name="WindowsService.exe"
                    Stop="both"
                    Remove="uninstall"
                    Wait="no" />

</Component>
2
What about the Start-Attribute? Seems like "demand" is a much more promising value than "start". wixtoolset.org/documentation/manual/v3/xsd/wix/…Stefan Wanitzek
Tried changing it to that, doesn't show up in services.mscdevfunkd

2 Answers

9
votes

Do not use the ServiceControl element as it is what will start and stop services. By calling it, you are asking the installer to do something with a service. You only need to call ServiceInstall to create a service. As Stefan Wanitzek suggested, you should use demand in the Start attribute of your ServiceInstall. This is to make your service not start running if the user reboots the computer. If your installer is also installing the .exe as welladd the file with the install service. I would suggest to use the following taken from your code:

<Component Id="ServiceInstaller" Guid="3e412e3d-0339-325c-8633-f54ffaaa4921">
        <File Id="WindowsService.exe" 
         Name="WindowsService.exe" 
         KeyPath="yes"
         Source="Path to the EXE"/>
        <ServiceInstall Id="ReportingServiceInstaller"
                Type="ownProcess"
                Vital="yes"
                Name="WindowsService"                    
                DisplayName="WindowsService"
                Description="Wickedly awesome and amazing service."
                ErrorControl="ignore"
                Account="NT AUTHORITY\LocalService"
                Start="demand"
                Interactive="no" />
</Component>
2
votes

devfunkd's solution is correct, but there are several issues that need to be discussed first.

One, you can eliminate ServiceControl, but you may also just remove the Start attribute. This helps with stopping the service at update. And no, Start doesn't have a "none" option, nor is it valid to write Start="", which would allow using a simple variable instead of copy pasting entire components.

Two, whenever a service is being updated, the RestartManager gets involved. If the service is running, the service is stopped, then the Setup does what it was instructed to do, including not starting the service, then RestartManager restores the original state of the service (started). I spent a day figuring THAT out.

Note that you could disable setup's interaction with RestartManager (see https://docs.microsoft.com/en-us/windows/desktop/Msi/msirestartmanagercontrol), but then you need to make sure you don't require a restart if the setup stumbles over files in use.

In other words, whether you remove ServiceControl altogether or only the Start attribute, in order to make sure the services are not started after an update you need to stop them manually before the setup.