After uninstalling certain programs or tools, unused services may still be present in Windows. This article explains how to properly remove a service in Windows using the built-in CMD or PowerShell tools.
The Services graphical management snap-in (services.msc
) in Windows only provides basic action buttons for starting, pausing, or stopping a service. This console cannot be used to remove the service.
For example, the task is to remove the unused Stunnel TLS wrapper service (in my case, this service was used to encrypt app traffic with Stunnel). First, get the service name. In this case, it is stunnel (copy the name from the Service name field).
Set-Service stunnel –startuptype disabled –passthru
Stop-Service stunnel
Also, before deleting a service, check the DependentServices parameter to see which other services depend on it.
Get-Service stunnel -DependentServices
You must stop the service before you can remove it. Click the Stop button in the Services console or run the command:
net stop stunnel
Service settings are stored in the registry under the HKLM\SYSTEM\CurrentControlSet\Services key.
Before deleting a service, back up its settings by exporting the service configuration to a REG file with the following command:
reg export "HKLM\SYSTEM\CurrentControlSet\Services\stunnel" "%HOMEPATH%\Documents\stunnel_backup.reg" /y
Now you can delete a service by its name using the built-in sc.exe
command (if the service name contains spaces, enclose it in quotation marks):
sc delete stunnel
A message should appear:
[SC] DeleteService SUCCESS
sc.ee \\m-fs01 stop ServiceName1
sc.exe \\m-fs01 delete ServiceName1
Or you can remove a service using PowerShell:
Remove-Service stunnel
In Windows PowerShell 5.1, which doesn’t contain the Remove-Service command, you can use WMI to remove a service:
$service = Get-WmiObject -Class Win32_Service -Filter "Name='stunnel'"
$service.delete()
Also, to remove a service, you can delete its registry key under HKLM\SYSTEM\CurrentControlSet\Services. To ensure you are targeting the correct service for removal, find the service in the list and verify that the DisplayName and ImagePath parameters contain the service’s name and the complete path to its executable file. Delete the entire service key.
F5
to refresh the Services console list and verify that the service has been removed and no longer appears. It is usually recommended to restart Windows after removing a service. After rebooting, you can delete the executable files and directories that are referenced by the ImagePath registry value.When deleting some services via the CMD, a message may appear saying the service is marked for deletion, indicating it is scheduled for removal but may require closing related handles or a system restart to complete the process.
DeleteService FAILED 1072: The specified service has been marked for deletion.
This service will be automatically removed after the computer restarts.
To remove a service without restarting Windows, use the taskill
command or terminate the service’s running executable process from Task Manager
. Then delete the service registry key using the following PowerShell command:
Get-Item HKLM:\SYSTEM\CurrentControlSet\Services\stunnel | Remove-Item -Force -Verbose