2

i am working on a service that is later deployed by a WIX installer. this is service installer class

this.ServiceInstaller.DisplayName = "My Service";
            this.ServiceInstaller.ServiceName = "MyService";
            this.ServiceInstaller.ServicesDependedOn = new string[] {
        "ServiceA",
        "ServiceB",
        "ServiceC"};

and this is the WIX installer code

    <Component Id="MyService.exe" Guid="{1234}">
        <File Id="MyService.exe" KeyPath="yes" Source="$system\$(sys.BUILDARCH)\MyService.exe">
          <netfx:NativeImage Id="MyService.exe" Platform="all" Priority="1" />
        </File>
        <ServiceInstall Id="MyService.exe" DisplayName="My OTHER Service" Name="MyService" ErrorControl="normal" Start="auto" Type="ownProcess">
          <ServiceDependency Id="ServiceD" />
          <ServiceDependency Id="ServiceE" />
          <ServiceDependency Id="ServiceF" />
          <util:ServiceConfig FirstFailureActionType="restart" SecondFailureActionType="restart" ThirdFailureActionType="restart" RestartServiceDelayInSeconds="10" />
        </ServiceInstall>
        <ServiceControl Id="MyService.exe" Name="MyService" Stop="install" Remove="uninstall" />
    </Component>

as far as i can tell, the configuration in the WIX completely overrides the settings in the project installer. (specifically name and dependencies) is this a default behavior? whats the point of having a serviceInstaller class if WIX is going to completely ignore it?

Danw25
  • 306
  • 2
  • 13
  • service can be also installed using `installutil.exe` – Pavel Anikhouski May 19 '20 at 15:02
  • 1
    ***ServiceInstaller classes*** are generally meant to be used **during development** for **testing purposes**. There are many ways to install services, but you should use the MSI tables `ServiceInstall` and `ServiceControl` if you can. – Stein Åsmul May 19 '20 at 19:17

1 Answers1

0

Cross Linking: A couple of similar answers: 1) Chris Painter on service credential preservation and / or handling, 2) Service debugging.


ServiceInstaller classes: This feature is generally meant to be used during development for testing purposes. You use the InstallUtil.exe .NET tool for installation and / or Visual Studio.


Prefer MSI: There are many ways to install services, but you should use the MSI tables ServiceInstall and ServiceControl if you can. Below are some further details on various more or less crazy options.


Service Registration Options: An old, classic document from Phil Wilson (MSI MVP and author of "The Definitive Guide to Windows Installer") listed a number of ways to install services by means of:

  • 1) MSI - ServiceInstall, ServiceControl tables - and a few others.
  • 2) Win32 - CreateService APIs.
  • 3) Registry - manually update, generally an undesirable "under-the-hood" option.
  • 4) WMI Classes - Win32_Service. Major benefit: Scriptable. Wraps CreateService (Win32).
  • 5) InstallUtil.exe - .NET tool & installer classes.
  • 6) MSI & Installer Class Custom Actions - calls InstallUtil.exe via the shim dll InstallUtilLib.Dll in Visual Studio Setup Projects - not a favorite option of mine. A lot of complexity for no gain basically. Just use the service tables in the MSI. Automagic.

InstallUtil.exe: When .NET arrived, a tool called InstallUtil.exe was introduced together with a set of installer classes in the .NET framework. The ServiceInstaller framework class contains code to install Services, and the developer can override the class methods to provide extra install-time code. This provides a useful way for developers to easily install Services for testing purposes.


Many years later one could add to Phil's list:

More exotic: Srvany (run app as service, very outdated - don't use).


Essential Service Tools: There are many essential tools for working with services such as: SC.exe, Services.msc, NET, etc... Process Explorer is good for more advanced debugging - for example what files your service holds locked that cause upgrade problems, or other problems. There is a list of any further tools here: https://installdude.com/jumpgate.php and click the "Debugging" label (towards top, under search box) and then click "Essential Service Tools".


Windows Services Frequently Asked Questions (FAQ): https://www.coretechnologies.com/WindowsServices/FAQ.html

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • the WIX installer is used as part of a larger product. its built just around the service. i'm not looking for alternatives, just to confirm my observation that settings from the serviceInstaller are overwritten. – Danw25 May 21 '20 at 05:41
  • I have [this old answer](https://stackoverflow.com/a/50375540) on a slightly different aspect of this (preserve settings on upgrade). Maybe skim it. And at least have a read of the section on ***"managed service account"*** - essentially to run the service with a password-less account so no credentials have to be added to your package. [Service accounts](https://learn.microsoft.com/en-us/windows/security/identity-protection/access-control/service-accounts). – Stein Åsmul May 21 '20 at 11:07
  • [Also see this recent answer from Chris Painter](https://stackoverflow.com/a/61882958). – Stein Åsmul May 21 '20 at 14:05