I'm writing a windows service using VS2010 and C# 4.0. The idea is to have multiple windows services installed using the same executable. To identify the current instance, I need to figure out the current service name of the instance.
The template in VS2010 derives the service from
. Who thinks that the property ServiceName in ServiceBase points to the according SCM service name, is wrong. ServiceName always contains the fixed string entered in the property dialog when creating the service. Removing it doesn't help either.
returns a list of all services (as a ServiceController object) on the machine. The ServiceController contains a property ServiceName as well, which contains also the name I'm looking for, but I don't know which ServiceController matches my service. Actually the name is exactly what I'm looking for. And if I have multiple services from the same executable, I cannot distinguishe them.
Does anybody have an idea how to get the name of the current service?