The Specified Service Has Been Marked For Deletion

Oh dear... The specified service has been marked for deletionIt’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!


not 100% sure if this works, but worth a crack

find the process id
sc queryex SERVICENAME

then bring down the hammer
taskkill /pid SERVICE_PID /f

or do it through task manager i guess

Thanks Ben, that will work in certain situations where the underlying service process is lingering but there are still some cases where the service process is no longer running, but “something” is still holding a lock on the service definition in the installed service database which causes this same error message. Unfortunately being able to pinpoint what that “something” is has eluded me for years (especially when “something” is a remote Services MMC).

Its works !!!

thanks Ben .. that worked like a charm!

Jimmy Flip Flops

This didn’t work for me but the below did (extra thing to try for some people?)

I did the query ex and it was showing as running but with a pid of 0!

I checked the registry and the image path had a \??\ prefix. I removed the prefix and I was then able to stop and delete the service and install the new one!

Leave a Reply