Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve "The specified service has been marked for deletion" error

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:

  • Stopped the service, obviously. The sc queryex "<service name>" gives the following result:

    SERVICE_NAME: Stub service         TYPE               : 10  WIN32_OWN_PROCESS         STATE              : 1  STOPPED         WIN32_EXIT_CODE    : 1067  (0x42b)         SERVICE_EXIT_CODE  : 0  (0x0)         CHECKPOINT         : 0x0         WAIT_HINT          : 0x0         PID                : 0         FLAGS              : 
  • Ensured that Microsoft Management Console is closed (taskkill /F /IM mmc.exe),

  • Ensured that Event Viewer is closed,

  • Removed the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<service name> from the registry.

    Due to this removal, services.msc still shows the service (with a name, but no status or startup type), but the description is “<Failed to Read Description. Error Code: 2 >”. When attempting to view the properties, “The system cannot find the file specified.” is shown five times.

The problem persists.

What is the next step?

like image 611
Arseni Mourzenko Avatar asked Dec 13 '13 08:12

Arseni Mourzenko


People also ask

How do you check if a service is marked for deletion?

Navigate to : HKLM\SYSTEM\CurrentControlSet\Services\YourService\DeleteFlag. Check for the the DeleteFlag entry of this service in Registry and check if it is there is and the value is set to "1". If it is, reset it to "0" and check for the result.


2 Answers

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 third 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.

like image 92
Arseni Mourzenko Avatar answered Oct 03 '22 10:10

Arseni Mourzenko


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

like image 24
forcedfx Avatar answered Oct 03 '22 10:10

forcedfx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!