Tundebabzy
Tundebabzy

Reputation: 879

Wix 3.11 - Installer Can't Start Service

Can anybody help me find out why my Windows service won't start.

When I install it with installutil, it works perfectly. I decided to use wix to create an installer for the end user but it won't start.

Here's my code

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="IWErpnextPoll" Manufacturer="IWW" Language="1033" Version="1.0.0.0" UpgradeCode="ccc3c2fe-d20f-45ce-b978-4dc7c84ce6c8">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />

        <Feature Id="ProductFeature" Title="IWERPNextPoll_Setup" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="IWErpnextPoll" />
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
            <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
            <Component Id="ProductComponent">
                <File Source="$(var.IWErpnextPoll.TargetPath)" />
                <ServiceInstall Id="ServiceInstaller" Name="IWErpnextPoll" Type="ownProcess" Vital="yes" DisplayName="ERPNext2Sage" Description="A background service." Start="auto" Account=".\LocalSystem" ErrorControl="normal" Interactive="no" />
                <ServiceControl Id="StartService" Name="IWErpnextPoll" Stop="both" Start="install" Remove="uninstall" Wait="yes" />
            </Component>
        </ComponentGroup>
    </Fragment>
</Wix>

The installer throws this error:

Service 'IWErpnextPoll' (IWErpnextPoll) failed to start. Verify that you have sufficient privileges to start system services

I ran the following in the command line:

msiexec /i IWERPNextPoll_Setup /l*v log.txt

but (my untrained eyes) didn't find anything that seemed off in the very very log file.

The service I wrote is my first forray into C#. I'll be very happy to get any pointers.

Upvotes: 0

Views: 196

Answers (2)

Tundebabzy
Tundebabzy

Reputation: 879

The answer by @Christopher Painter and the comments on my question led me towards the problem.

The problem was that I did not include my project dependencies in product.wsx. I had to add like so...

...
<Component Id="Serilog.dll">
    <File Source="$(var.IWErpnextPoll.TargetDir)Serilog.dll" />
</Component>
<Component Id="Serilog.Settings.AppSettings.dll">
    <File Source="$(var.IWErpnextPoll.TargetDir)Serilog.Settings.AppSettings.dll" />
</Component>
<Component Id="Serilog.Sinks.File.dll">
    <File Source="$(var.IWErpnextPoll.TargetDir)Serilog.Sinks.File.dll" />
</Component>
<Component Id="RestSharp.dll">
    <File Source="$(var.IWErpnextPoll.TargetDir)RestSharp.dll" />
</Component>
...

After this, things started working as expected

Upvotes: 0

Christopher Painter
Christopher Painter

Reputation: 55620

99.99% of the time this is a problem with the service.

A couple of pro tips.

1) Don't author the ServiceControl element for the first few builds until you know the thing is solid. Test the service after installation.

2) If you do author it, let it sit on the failed to start dialog and start profiling. Run the EXE from a command prompt and see if it is missing dependencies or throws errors. Have lots of logging code in the service to understand what is wrong.

ServiceInstaller is a form of self registration anti pattern. Perhaps you had some code in there doing something like creating an EventSource or a registry key and without it your service is throwing an exception.

Only profiling/debugging will tell for sure.

Upvotes: 1

Related Questions