It’s release day for the latest version of one of your Windows service applications. You’ve got a set of new binaries and a pocket full of dreams… and a rollback procedure. When your maintenance window arrives it’s go time. But your uninstall procedure is taking longer than usual. Something must be wrong. What’s going on? You check your deployment process’ logs and you get that sinking feeling in your stomach when you see the error in the log file: “the specified service has been marked for deletion”.
This error can be one of the scariest for Windows application operators and DevOpelers – you just want to remove the service definition from the Service Controller, but can’t for some reason. Even your manual attempts at running an “sc delete” are met with the same error message – “the specified service has been marked for deletion”. Typically the solution is one of the most brute force options available: reboot the box.
Typically this error message happens because something else has locked the installed service database. While a reboot will certainly clear all of the locks, before you pull out that sledge hammer, there are a few other tricks you can try.
Close Your MMCs
If you have any Services MMCs running locally on the computer in question, or running remotely on another computer, but connected to the server your application is installed on – close it. The Services MMC is the most common reason behind the “specified service has been marked for deletion” error message. Generally just closing Services MMC will free up the lock and allow you to delete the service definition.
Close Other People’s MMCs
If you’re absolutely certain you don’t have any Services MMCs running on the computer in question or anywhere else, make sure no one else is running one on or connected to the computer as well. This can be as simple as starting up Task Manager or running pslist and looking for any “mmc.exe” on the computer your application is installed on. While not every mmc.exe is a Services MMC, it’s a lot less intrusive to ask other people to close their MMCs (both local and remote) than to reboot a whole server just to delete one service.
Hopefully these tricks help keep your blood pressure lower during a Windows Service deployment. One thing I’ve never been able to figure out, but would love to know is a way to programmatically see who or what specific PID and client host name is locking the service controller database. If you have a way, let us know in the comments below!