1

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?

Laurent Michel
  • 1,069
  • 3
  • 14
  • 29
  • IIRC, you can reproduce the same with `installutil` logic in wix, or even call `installutil` during msi installation, created using wix. Which installer have you tried already? – Pavel Anikhouski Mar 26 '20 at 08:11
  • Sorry, I'm a little confused by your question. Are you wanting to do this using only Advanced Installer or are you open to using WiX? – Ryan Thomas Mar 26 '20 at 08:11
  • 1
    I too was struggling with similar issues with winservices until I discovered topShelf (https://www.nuget.org/packages/TopShelf). All of a sudden winservices got super easy to create, test and deploy as you only create regular console applications and install them by command line parameters to the console app itself. Maybe this can be an alternative for you too? Good luck. – DaggeJ Mar 26 '20 at 08:18
  • I have tried WiX until I learned that in my team we only use Advanced Installer. – Laurent Michel Mar 26 '20 at 08:43
  • I will try and ask to use topshelf. That seems to be a pretty nice tool. Thanks for the advice! – Laurent Michel Mar 26 '20 at 08:51

1 Answers1

0

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.

alby98
  • 37
  • 4