trio.so
Explained

How to Delete a Windows Service From the Command Line

How to delete a Windows service with sc delete or PowerShell, fix "marked for deletion", and what to check first. One PC or many.

Mountain landscape representing leadership perspective and vision
Written by
Atena Ladchartabi

Content writer, trio.so

Published on
Modified on

To delete a Windows service, open Command Prompt as administrator and run sc delete ServiceName. A successful run prints "[SC] DeleteService SUCCESS". Before you run it, stop the service and back up its registry key, because a deleted service is gone until you restore it.

Before you delete: find the service name and check what it is

The command needs the service name, not the display name. Find it in a Command Prompt run as administrator:

sc query state= all | findstr /i "SERVICE_NAME DISPLAY_NAME"

Or in PowerShell:

Get-Service | Where-Object DisplayName -like "*vendor*" | Select-Object Name, DisplayName, Status

Check what the service runs:

sc qc ServiceName

Read BINARY_PATH_NAME and TYPE. A path in C:\Windows\System32 or a driver type means a Windows component. Do not delete those. Delete services that belong to software you have already uninstalled, or to an app you installed on purpose.

Delete a service with sc delete

  1. Stop the service: sc stop ServiceName
  2. Back up its registry key: reg export HKLM\SYSTEM\CurrentControlSet\Services\ServiceName service-backup.reg
  3. Delete it: sc delete ServiceName
  4. Check it is gone: sc query ServiceName should answer that the service does not exist.

The service disappears from the Services console when you refresh it, or after a restart.

Remove a service with PowerShell

PowerShell 6 and later has Remove-Service:

Remove-Service -Name "ServiceName"

Microsoft introduced it in PowerShell 6.0, so it does not exist in Windows PowerShell 5.1, the version built into Windows. In 5.1, call the executable, and write sc.exe with the extension, because sc alone is an alias for Set-Content in PowerShell:

sc.exe delete ServiceName

You can also use WMI: (Get-CimInstance Win32_Service -Filter "Name='ServiceName'") | Invoke-CimMethod -MethodName Delete.

Remove service cmd: delete a service on another PC

Use sc.exe \\PCNAME delete ServiceName from an admin account that has rights on the remote PC, or run the command in a remote PowerShell session with Invoke-Command. Microsoft notes that the service cmdlets have no ComputerName parameter, so Invoke-Command is the route.

Fix "The specified service has been marked for deletion"

Error 1072 means the service is deleted but something still holds it open. Windows finishes the removal when the last handle closes.

  1. Close the Services console (services.msc), Computer Management, Event Viewer and Task Manager, which hold handles.
  2. Stop the process the service ran: find it with sc queryex ServiceName, then taskkill /pid 1234 /f.
  3. If it is still stuck, restart the PC.

Other errors:

  • Access is denied (5): the prompt was not run as administrator.
  • 1060: the service name is wrong or it was already deleted.

Registry fallback

If sc delete cannot do it, delete the key HKLM\SYSTEM\CurrentControlSet\Services\ServiceName and restart. Export the key first. Use this as a last resort. Deleting the key by hand skips the checks that sc delete runs.

Disable first, delete later

Disabling is the safer first step: sc config ServiceName start= disabled (with the space after =). Leave the service disabled for a week. If nothing breaks, delete it. See also how to disable startup programs.

Delete a service on many PCs

Put the stop, export and delete steps in a script and run it on a test PC first.

Managing this across many devices

trio.so can run a script on enrolled Windows PCs from the console, and can start, stop and restart services on them. Deleting a service is still done by your script. See remote terminal.

The trio.so console showing the services on a Windows PC, with start, stop and restart actions.
Start, stop and restart services on an enrolled Windows PC from the trio.so console.

Related reading: PowerShell execution policies and enable System Protection from the command prompt.

Ready-to-use Templates

Must-have Template Toolkit for IT Admins

Explore All
Template Toolkit

Start, stop or restart Windows services across the fleet

trio.so controls Windows services remotely on every managed PC, and runs scripts from the same console. Start a 14-day free trial.

Start free trial

Manage Every Device From One Console

trio.so brings device management, patching and security policies for Windows, macOS, Linux, iOS/iPadOS and Android into one console. Enroll a device and see it in the console within minutes.

14-day free trial. No credit card required.

trio.so brings device management, patching and security policies for Windows, macOS, Linux, iOS/iPadOS and Android into one console. Enroll a device and see it in the console within minutes.

Smiling womanAbstract geometric patternAbstract geometric patternSmiling womanSmiling woman

Frequently Asked Questions (FAQ)

Have questions? We've got answers. This section covers some of the most commonly asked questions related to this topic.

Run sc delete ServiceName in an administrator Command Prompt, after stopping the service and exporting its registry key.

Use sc delete in Command Prompt, sc.exe delete in Windows PowerShell 5.1, or Remove-Service in PowerShell 6 and later.

Close the Services console and any tool that has the service open, end the service's process, then restart if it persists.

Related

From the blog

The related industry news, interviews, technologies, and resources.