Is there a way to get the service name from C# that the current service was registered with when it was installed.
For instance, I register the same service twice:
sc.exe create ServiceName1 binPath= D:\myservice.exe
sc.exe create ServiceName2 binPath= D:\myservice.exe
In my service, I actually want to know if I am ServiceName1 or ServiceName2. But there seem to be no way to do that.
I tried calling ServiceBase.ServiceName
prior to setting it, but it is just empty.
I tried ServiceController.GetServices().Where(svc => svc.ServiceHandle.DangerousGetHandle() == myservice.ServiceHandle)
but it seems to get another handle, so they are not compareable.
There is a special program called SRVANY.exe
and that seems to be able to do it. The question is just how it does so.