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>
You just need to create a new WiX project, add your app files, and then build the project. That's it! To create a new WiX project, open Visual Studio and go to File > New > Project. In the New Project dialog, select the “WiX Toolset” template from the list of available templates.
Go to Tools -> WiX Setup Editor. On the left under Root Directory choose InstallFolder. Under Projects to install, choose the project you want to install. In the red area to the right, you'll see a list of files.
Right-click on “Custom action > Add Custom action”. Open a dialog box “Select Item In Project” then double-click on “Application Folder” then click on the “Add Output” button. Open a dialog box, choose your project (Window service) and “Primary Output” from (Active) and click on the OK button.
Adding a WiX setup project In Visual Studio, open your solution, and add a WiX project to it: go to the Visual Studio main menu and click File -> Add -> New Project to open the Add New Project dialog. Choose the Setup Project item in the Windows Installer XML node, specify the project name and click OK.
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With