I’ve noticed that sc delete ServiceKeyName won’t work if services.mmc is open. It marks it for deletion (whatever! That just means it doesn’t do what I want as far as I’m concerned).
My question is: Is there a method for deleting a service that will work regardless whether services.mmc is open or not? or should I ensure any instances of services.mmc are closed before I try to delete it?
I’m looking into using DeleteService
http://msdn.microsoft.com/en-us/library/ms682562%28v=VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms682571%28v=VS.85%29.aspx
But it also talks of closing handles and similar excuses for why it cannot do what the user has asked to be done immediately. So if DeleteService is going to also require that services.mmc is closed, then I’ll stick to sc delete and kill process on services.mmc instead of implementing DeleteService. I want a method that does what it advertises (no excuses – no waiting for anything).
In order to achieve this you would need the services MMC snap in to close and reopen its handle to the service control manager. It won’t do this and thus you have to accept the behaviour as is.