Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WiX MSI install Windows service without starting it

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>
like image 872
devfunkd Avatar asked Dec 02 '15 15:12

devfunkd


People also ask

How do I create a Windows Installer MSI .NET core WiX?

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.

How do I create a simple MSI installer using WiX?

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.

How do I create a MSI service?

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.

How do I create a WiX Windows Installer?

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.


2 Answers

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>
like image 85
ProjectNapalm Avatar answered Nov 02 '22 01:11

ProjectNapalm


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.

like image 38
Siderite Zackwehdex Avatar answered Nov 02 '22 01:11

Siderite Zackwehdex