How to install windows services written in .Net with an installer package?

2.1k Views Asked by At

I followed thoroughly the Microsoft Tutorial: Create a Windows service app. In particular, I saw this code:

static void Main(string[] args)
{
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[]
    {
        new MyNewService(args)
    };
    ServiceBase.Run(ServicesToRun);
}

With the corresponding ProjectInstaller, also described in the tutorial, I was able to successfully install the service in the way described in the tutorial with installutil.

Now, the above code suggests that I can install an array of services with that program. For example, I've built up several services, and come up with code of the following kind:

static void Main(string[] args)
{
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[]
    {
        new Service1(args),
        new Service2(args),
        new Service3(args),
        new Service4(args)
    };
    ServiceBase.Run(ServicesToRun);
}

Again, with the corresponding ProjectInstaller, installing those 4 services with installutil is fine. I get my services installed and I can even run them.

However, I was not able to find a way to pack this into an installer package. Microsoft documentation mentions ClickOnce, WiX, and InstallShield package installers. In my development team, we use Advanced Installer. None of those installer packages seem to show in their documentation how to install services with the above 4-services Main program. Every time, I see how to install one single service at a time. I could for example write one of the above Main program for each of my services and pack those programs in my installer package.

Is it possible? How? I don't really want to create one visual studio project for each of my services just to install them. What possibilities do I have if I can't make it happen with the above array of services?

1

There are 1 best solutions below

0
On

you can try to use a setup project that includes all the services to be installed. But you need to install the Microsoft Visual Studio Installer Project plugin (box icon) this is a guide that could help you: https://www.c-sharpcorner.com/UploadFile/b7531b/create-simple-window-service-and-setup-project-with-installa/ Maybe when you add custom action on the setup project you can add more services to include in the setup file.