Is there a way to get the name of the service from C # with which the current service was registered when it was installed.
For example, 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 really want to know if I am ServiceName1 or ServiceName2. But there seems to be no way to do this.
I tried calling ServiceBase.ServiceName before installing it, but it is just empty.
I tried ServiceController.GetServices().Where(svc => svc.ServiceHandle.DangerousGetHandle() == myservice.ServiceHandle) , but it seems to get another descriptor, so they are not comparable.
There is a special program called SRVANY.exe and it looks like it can do it. The question is how this is done.
source share