A way to detect if a service is being uninstalled

191 views Asked by At

I have a service I created with TopShelf and there is a BeforeUninstall event which runs some code before the service is uninstalled, but this only runs if the user uninstalls the service through cmd, but if the user uses Remove-Service from powershell the event is not fired.

So my question is, is there any way to fire an event when a service is uninstalled regardless from where the user uninstalls it?

p.s. the reason I need this before uninstall event is because some other services are dependent on this service and they have to be stopped before the serivce is uninstalled.

1

There are 1 answers

0
ktm root On

Did you look in the event viewer for Event ID 1034 OR 11724(software package is removed successfully)? Alternatively, you can run sc query [servicename]. Result 1060 will indicate the service does not exist.