Yuval Peled Yuval Peled - 1 month ago 9
C# Question

Install a .NET windows service without InstallUtil.exe

I have a standard .NET windows service written in C#.

Can it install itself without using InstallUtil?
Should I use the service installer class? How should I use it?

I want to be able to call the following:


MyService.exe -install


and it will have the same effect as calling:


InstallUtil MyService.exe

Answer

Yes, that is fully possible (i.e. I do exactly this); you just need to reference the right dll (System.ServiceProcess.dll) and add an installer class...

Here's an example.