4

I have a project which includes 2 windows services. I create a ProjectInstaller to install these items, which works fine. But I have a question; given the code defined below, how does the project installer know which service to install for serviceInstaller1 and which for serviceInstaller2?

Is it simply based upon the ServiceName?

[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
    private ServiceProcessInstaller process;
    private ServiceInstaller serviceInstaller1;
    private ServiceInstaller serviceInstaller2;
    public ProjectInstaller()
    {
        InitializeComponent();
        try
        {
            process = new ServiceProcessInstaller();
            process.Account = ServiceAccount.LocalSystem;
            serviceInstaller1 = new ServiceInstaller();
            serviceInstaller1.ServiceName = "xxx";
            serviceInstaller1.Description = "Does Something";
            serviceInstaller1.StartType = ServiceStartMode.Automatic;

            serviceInstaller2 = new ServiceInstaller();
            serviceInstaller2.ServiceName = "yyy";
            serviceInstaller2.Description = "Does something else";
            serviceInstaller2.StartType = ServiceStartMode.Automatic;
            Installers.Add(process);
            Installers.Add(serviceInstaller1);
            Installers.Add(serviceInstaller2);
        }
        catch (Exception ex)
        {
            throw new Exception("Failed", ex);
        }
    }
}
Alex Aza
  • 76,499
  • 26
  • 155
  • 134
Mick Walker
  • 3,862
  • 6
  • 47
  • 72

1 Answers1

4

It is based on ServiceName.

Installer doesn't really care about the name, you can supply pretty much any name and installer will be happy to register a Windows service with this name for you, but when you attempt to start service it will fail, unless it finds service in your assembly that has ServiceName matching to the ServiceName specified in the installer.

Error 1083: The executable program that this service is configured to run in does not implement the service.
Alex Aza
  • 76,499
  • 26
  • 155
  • 134
  • Just a further question, when deploying with only one service, I am assuming the name doesnt matter, as it simply installs the first service it finds. Is this correct? – Mick Walker May 18 '11 at 08:53
  • 2
    @Mick Walker - If you have one service in the installer, and you supply one or more services to `ServiceBase.Run()` method, the first service in the collection will be used despite the service name. – Alex Aza May 18 '11 at 15:59
  • 2
    What if I need to create two services from one assembly with different credentials? – Kobor42 Oct 18 '13 at 14:15