0

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.

Tundebabzy
  • 829
  • 2
  • 11
  • 24
  • 1
    Have a look at this [thread](https://stackoverflow.com/questions/16188495/failed-to-install-and-start-windows-services-in-wix-installer) and [this](https://stackoverflow.com/questions/12370634/cant-start-windows-service-with-wix). [this](https://stackoverflow.com/questions/20956595/wix-installer-verify-that-you-have-sufficient-privileges-to-start-system-servic) might be also helpful – Pavel Anikhouski Apr 27 '20 at 19:04
  • 1
    Check the **event log**, check for **missing runtimes** (testing on barebone virtual?), **enable any debugging in your service component** - for example **logging**, come to think of it here is more: [previous answer on service startup problems](https://stackoverflow.com/a/61149858/129130). – Stein Åsmul Apr 27 '20 at 19:39

2 Answers2

1

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.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
0

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

Tundebabzy
  • 829
  • 2
  • 11
  • 24