Search code examples
c#windows-serviceswcf-hosting

C# register the same windows service with different parameters


I need to create many windows services to host many WCF Service so I can stop a single one (for example to update it) and keep the other running.

Since I don't want to create a windows service for every WCF Service I have, I'm trying to create a C# application that can register itself as a windows service but with different parameters (and service name of course).

For example calling it this way:

MyService.exe /install WcfService1.dll
MyService.exe /install WcfService2.dll

This creates two different windows service like these:

WcfService1 -> MyService.exe /run WcfService1.dll
WcfService2 -> MyService.exe /run WcfService2.dll

I can't find a way to do this other than editing directly the registry.


Solution

  • I've found a nicer way to do it: sc.exe

    sc.exe create WcfService1 binPath= "MyService.exe /run WcfService1.dll"

    so I just need to create a bat/cmd to launch this command.