Miscellaneous Debris

Avner Kashtan's Frustrations and Exultations

Windows Services, services.msc and the "This Service is marked for deletion" error.

In my current project, we have a windows service that we are developing and debugging, which involves a lot of installing/uninstalling the service. One common problem when uninstalling a service is that while the uninstallation is successful, you still see the service listed in the Services console(services.msc). If you try to start it, stop it or uninstall it again (using installutil.exe or sc delete) you get an uninformative "This service has been marked for deletion".

The KB article about this problem suggests you restart the computer, which is pretty much overkill. Sure, it'll work, but you'll never find out what caused it in the first place. Turns out it's a pretty simple affair: just make sure you close the Services console, which apparently holds a handle of some sort to it. You don't have to do it before you uninstall. The minute you close the console, all services marked for deletion will be deleted, and all will be well.

When doing it on a server, it's important to make sure you've closed all Services consoles on all active sessions. I've seen this error happen when no console was open, and it was fixed by running Task Manager and killing all instances of mmc.exe. I could have logged on to the other sessions and closed it gracefully, but I was lazy. Did the trick.

Comments

THANK YOU! said:

This was driving me crazy.  I am working on a service and have to uninstall/reinstall it repeatedly, but sometimes I accidentally uninstall twice in a row and this happens.  Hurray for internet search :)

# April 16, 2008 6:26 PM

martin r davissr said:

the window service.msc for deletion error pleae rover this my desk top I RUN windows XP ON MY DESKTOP

# April 22, 2008 9:16 PM

rpgivpgmr said:

Thank you Avner.

Looks like Microsoft Needs You!

# April 23, 2008 8:31 AM

Justin said:

Just what I needed to know!

# July 15, 2008 1:38 PM

Salman said:

what r the services that run when MOM is running.

# August 24, 2008 8:39 PM

ctupper said:

Thanks much!!! I hate rebooting.

# September 23, 2008 2:42 PM

KVK Consultancy said:

Good Article. Know exactly how you felt.

# October 9, 2008 8:39 AM

Very Greatfull!!!!! said:

Thank you!

Some shameless plugs:

without reboot

delete services without reboot

nt services wont remove

windows services wont remove

"This Service is marked for deletion"

# November 7, 2008 4:41 PM

Colby said:

THANK YOU VERY MUCH

# November 14, 2008 4:53 PM

Dan Hintea said:

Thanks for the tip!

# November 15, 2008 4:18 PM

Anand Muddi said:

Thanks!! This really helped.

# December 15, 2008 5:37 AM

kaushalparik27 said:

Thanks!! This really helped.

# March 2, 2009 3:53 AM

PeterBrunone said:

Wow.  I can't believe I had to google for a blog post to get an answer for this.

Thank you for writing this up so I didn't have to keep restarting my computer all night.

# April 12, 2009 3:29 AM

Rohonesh Kar said:

Thanks so much for this.. this restarting or logging off the system was driving me crazy.. Actually felt foolish on realizing that the solution was so simple..

# May 27, 2009 6:43 AM

Ajay Kewale said:

That's what I wanted..Thanks!!!

# June 22, 2009 10:48 AM

yayai said:

OMG me life saver!

# June 26, 2009 5:50 AM

Miahoo said:

Man, ty!! it just drive me crazy!

and such a simple solution. i LOL`ed!

# September 23, 2009 5:21 AM

ruben ruvalcaba said:

Wow! you're the man

# November 2, 2009 1:57 PM

Wilson Edgar said:

I'll just add another (and much deserved)

Thank you.

# November 25, 2009 5:57 AM

Nic said:

Unable to start http using net start http

Driver is blocked

# March 7, 2010 2:11 AM

Charles said:

Genius I had been staring at that stupid service for an hour should have known to close and open the window

Cheers

# June 14, 2010 3:36 PM

cn_kevin said:

I find no active sessions,

no instances of mmc.exe.

but it doesn't work well.

so I'am delete it twice,.

# December 3, 2010 4:34 AM

remo said:

Thanks!

google + you  = FTW

# January 23, 2011 4:54 AM

Chris said:

Thanks man, helped me too!

# February 15, 2011 3:33 PM

Neleus said:

I was uninstalling MySQL server and faced with the same problem. I killed all mmc processes and then reopened Services to see how it helped but the service was there still. I guessed that msiexec process could also hold that service. And after restarting uninstall it helped.

Thanks!

# March 2, 2011 5:28 AM

weblogs.asp.net said:

Windows services services msc and the quot this service is marked for deletion quot error.. Awful :)

# April 2, 2011 6:21 AM

b_man said:

Thanks!  This got me pointed in the right direction, but it wasn't any MMC causing my grief -- It seems that Process Explorer from SysInternals/MS can also keep open handles to services.

# September 3, 2011 6:20 PM

Tommy said:

Thx, solved another similar problem for me!

# October 7, 2011 2:29 AM

Fred said:

I confirm that also Process Explorer from Sysinternals seems to keep some handles. Closing that the solution works fine!

bye and thank you

Valerio

# March 8, 2012 8:33 AM

Nah said:

Simple and brilliant. Thanks

# March 17, 2012 7:21 PM

Bunnynut said:

This really cracked me up.

I have had this problem for a couple of times and decided to restart the develop server (I should apply for a job at MS), which works obviously.

I cant believe the solution is this simple, thanks for posting this.

# August 2, 2012 3:30 AM

B Jansen said:

Thanks, this saved me a lot of reboots!

# October 22, 2012 9:35 AM

Gabrielle said:

brillant. this just saved me.

# October 29, 2012 7:17 PM

Waldo said:

Thanks Man, this helped a lot

# January 4, 2013 9:55 AM