Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I try to remove a Windows Service with sc delete <service name>, and encounter the following error:

[SC] DeleteService FAILED 1072:

The specified service has been marked for deletion.

What I've already done:

The problem persists.

What is the next step?

share|improve this question
1  
A reboot should normally clear up any lingering state. – Damien_The_Unbeliever Dec 13 '13 at 9:27
7  
I know. But I thought about a less radical solution. Rebooting thirty times per day won't be an acceptable solution in my case. – MainMa Dec 13 '13 at 9:32
15  
"why are you deleting services this regularly?": I'm writing a Windows service. Each time it is compiled, it should be restarted. "Yet hacking around in the registry 30 times per day is acceptable?": totally. Removing a key from registry doesn't force me to save everything, close every opened app, wait for a minute, and then reopen everything. – MainMa Dec 13 '13 at 9:59
25  
I've written windows services. Unless you're changing the actual code that performs the registration, there's no need to uninstall and reinstall it every time you do a build. So long as the path is still the same, the older registration information will still be valid. – Damien_The_Unbeliever Dec 13 '13 at 10:05
1  
I didn't know that. Thank you for the hint. – MainMa Dec 13 '13 at 10:07
up vote 560 down vote accepted

There may be several causes which lead to the service being stuck in “marked for deletion”.

  1. SysInternals' Process Explorer is opened. Closing it should lead to automatic removal of the service.

  2. Task Manager is opened.

  3. Microsoft Management Console (MMC) is opened. To ensure all instances are closed, run taskkill /F /IM mmc.exe.

  4. Services console is opened. This is the same as the previous point, since Services console is hosted by MMC.

  5. Event Viewer is opened. Again, this is the same as the first point.

  6. The key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\{service name} exists.

  7. Someone else is logged into the server and has one of the previously mentioned applications opened.

  8. An instance of Visual Studio used to debug the service is open.

share|improve this answer
1  
Task manager seems to do the same. And as noted below leaving the Services console open could cause this too. – CodingBarfield Feb 7 '14 at 8:31
1  
...and if closing all these still does not help and you still see the service as "marked for deletion" do simple log off instead of full restart. it helped me a few times. – Nedko Jun 2 '14 at 16:17
1  
One common workflow: your nefarious colleagues are also logged into the remote server, and they all have something open... – Chris O Jul 24 '14 at 17:50
15  
Closing the services console solved this problem for me! My process was the following: In the VS2012 x64 Native Tools Command Prompt --> Navigate to directory with service exectuable --> installutil /u servicename.exe (to uninstall the obsolete service) --> copy over new built service exe --> installutil servicename.exe (to install the updated service). I generally can uninstall and reinstall right away with no problems. Until I randomly can't. Closing the services console solved it. Thanks for the tip! – thehelix Nov 11 '14 at 20:18
6  
Process Explorer is the big one here, in my opinion. I suggest bolding it and/or moving it to the top of the list. – Coxy Sep 17 '15 at 9:12

This can also be caused by leaving the Services console open. Windows won't actually delete the service until it is closed.

share|improve this answer
1  
As I indicated in my question, “Microsoft Management Console is closed” during the tests. – MainMa Jan 23 '14 at 14:12
8  
In my case the Services console was the problem. As soon as I closed it and reopened it the deleted services went away. – Farrukh Najmi Apr 24 '14 at 21:34

In my case it worked after closing the Services. Check if the Services.msc is open, if yes close it and check any process of service is found in Task Manager.

share|improve this answer
    
Worked for me, thanks. – Delphi.Boy Nov 29 '15 at 1:41

hi guys i had the same problem

finaly i decide to kill service procces

for it try below steps

1- get procces id of service with

sc queryex <service name>

2- kil procces with

taskkill /F /PID <Service PID>

share|improve this answer
    
my PID is 0 so I had better not kill that! – rob Jun 10 at 15:50
    
you can uninstall service for it do below steps 1- run cmd 2- change direction to .exe file of your service locate that 3- execute command installutil /u <yourfilename.exe> – Ali Sadri Jun 16 at 6:45

In my case, it was caused by unhandled exception while creating eventLog source. Use try catch to pin point the cause.

share|improve this answer

Discovered one more thing to check - look in Task manager - if other users are connected to this box, even if they are 'disconnected' you have to actually sign them out to get the service to finally delete.

share|improve this answer
2  
Unnecessary. You just have to ensure everybody exits the Microsoft Management Console (MMC) and Services control panel. – EJP Jul 8 '15 at 4:05

Deleting registry keys as suggested above got my service stuck in the stopping state. The following procedure worked for me:

open task manager > select services tab > select the service > right click and select "go to process" > right click on the process and select End process

Service should be gone after that

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.