Effortlessly Delete a Windows Service Using CMD or PowerShell: A Step-by-Step Guide

After uninstalling certain programs, it’s not uncommon for leftover services to remain in Windows. This guide will explain how to properly delete a service using the built-in CMD or PowerShell tools, as the Services console (services.msc) only allows basic operations like starting, pausing, or stopping services, but not removing them.

Steps to Delete a Windows Service

  1. Identify the Service:To remove a service, you must know its name. For example, if you’re removing the Stunnel TLS wrapper service, the service name is stunnel. You can find this name in the Service’s properties.

  2. Disable the Service (Optional but Recommended):Before deletion, it’s prudent to disable the service and observe its behavior. You can disable it with the following PowerShell command:

    Set-Service stunnel –Startuptype Disabled –PassThruStop-Service stunnel
  3. Stop the Service:You need to stop the service before deletion. This can be done through the Services console or with the command:

    net stop stunnel
  4. Back Up Service Configuration:It’s wise to back up service settings which are stored in the registry. You can export the service configuration to a REG file with:

    reg export "HKLMSYSTEMCurrentControlSetServicesstunnel" "%HOMEPATH%Documentsstunnel_backup.reg" /y
  5. Remove the Service:You can delete the service using the sc.exe command:

    sc delete stunnel

    If successful, you should receive a message indicating the service was deleted.

  6. Using PowerShell to Remove the Service:If you’re using PowerShell Core version 6.x or newer, you can directly remove a service with:

    Remove-Service stunnel

    For Windows PowerShell 5.1, use WMI:

    $service = Get-WmiObject -Class Win32_Service -Filter "Name='stunnel'"$service.Delete()
  7. Deleting Registry Entry (Advanced Method):As a last resort, you can manually delete the service registry key. Ensure the target service is correct by checking if the DisplayName and ImagePath in the registry match the service you’re intending to delete. Delete the entire service key from:

    HKLMSYSTEMCurrentControlSetServices
  8. Refreshing the Services Console:After completion, press F5 in the Services console to verify that the service has been removed. A system restart may be necessary for changes to take full effect.

Additional Notes

When attempting to delete some services via CMD, you might see a message indicating that the service is marked for deletion, which typically means it’s queued for removal but may require a restart to finalize the process. Alternatively, you can use the taskkill command or terminate the process from the Task Manager before deleting the service registry key.

For further guidance on accessing and managing services, you may refer to related articles on removing services in PowerShell.


Posted

in

,

by

Tags: