OS

Uninstall .NET Windows Service Without Files: sc delete

Remove orphaned .NET Windows Service from services.msc when files are deleted using sc delete command. Step-by-step guide covers preparation, PowerShell alternatives, troubleshooting errors like access denied, and registry fallback—no reinstall needed.

1 answer 1 view

How do I uninstall a .NET Windows Service when the service files no longer exist? I installed a .NET Windows Service using InstallUtil but forgot to run ‘InstallUtil /u’ before deleting the files. The service is still listed in the Services MMC. What is the proper method to remove the service entry without the original files, and do I need to modify the registry or is there a better approach?

To uninstall a .NET Windows Service when the original files are deleted, run sc delete "ServiceName" from an elevated Command Prompt—this wipes the service entry from Windows Services (services.msc) without needing the files or manual registry edits. First, stop the service with net stop "ServiceName" if it’s running, and close any open Services MMC to release handles. No reinstallation required; just refresh services.msc afterward, and it’s gone.


Contents


Why the Service Lingers After File Deletion

Ever installed a .NET service with InstallUtil.exe, deleted the EXE and DLLs to clean up, only to find it stubbornly listed in services.msc? That’s because Windows services live primarily in the registry under HKLM\SYSTEM\CurrentControlSet\Services, not just the files. Deleting executables orphans the entry—it’s like a ghost in the machine. No panic; Microsoft explicitly recommends handling this without the original files.

The good news? You don’t need to dig into regedit unless all else fails. Tools like sc delete target that registry spot directly and safely.


Primary Method: Use sc delete to Uninstall Windows Service

This is the go-to fix for uninstalling a Windows service sans files. Open an elevated Command Prompt (right-click CMD > Run as administrator) and fire off:

sc delete "YourExactServiceName"

Replace “YourExactServiceName” with the precise name from services.msc—case-sensitive, and quote it if spaces are involved (e.g., sc delete "My .NET Service"). Hit enter, then check services.msc; refresh or reopen it.

Why does this work magic? The sc utility (Service Control) queries and nukes the registry entry atomically. As detailed in Microsoft’s service management docs, it’s the official path for orphaned .NET services post-InstallUtil.

Quick verify first: sc query "ServiceName" lists it if present. Success shows “SUCCESS” and removes it instantly in most cases.


Preparation Steps: Stop the Service and Close Handles

sc delete can balk if the service runs or holds open handles. Start here:

  1. Stop it: net stop "ServiceName" (or from services.msc: right-click > Stop).
  2. Kill MMC: Close services.msc entirely—it’s notorious for locking handles.
  3. Check for processes: Rarely, a PID lingers. Run sc queryex "ServiceName" for the PID, then taskkill /F /PID 1234.

Overlooked this once? I have—leads to “marked for delete” limbo until reboot. But usually, these steps free it up without restarting Windows.


.NET Specific: InstallUtil /u If You Can Restore Files

Tempted to recreate files for a proper uninstall? Possible, but overkill. Copy back the EXE/DLLs temporarily, then:

InstallUtil.exe /u "YourService.exe"

Run from the service’s folder as admin. This reverses InstallUtil’s registry changes cleanly. Per this Stack Overflow classic, it’s viable if files are recoverable, but sc delete skips the hassle.

Delete files again post-uninstall. Pro tip: Next time, script both install and uninstall.


PowerShell Options to Remove Windows Service

Prefer scripts? PowerShell’s got you, especially on modern Windows.

For PS 6+: Remove-Service -Name "ServiceName" -Force. Simple as that in an elevated PS window.

Older PS? WMI route:

powershell
$service = Get-WmiObject -Class Win32_Service -Filter "Name='ServiceName'"
$service.Delete()

Both zap the registry entry. Microsoft docs endorse this for automation—great for batch-removing orphaned services.

What if it’s stubborn? Combine with Stop-Service first.


Troubleshooting Common Errors

sc delete fails? Here’s the fix table:

Error Cause Solution
[SC] DeleteService FAILED 1072 Marked for delete, handles open Close MMC, reboot, or kill PID via sc queryex + taskkill
Access denied (5) Not elevated Run CMD/PS as admin
Service not found Wrong name sc query state= all to list exactly
1058: Service can’t stop Dependencies sc config "ServiceName" depend= / then stop

From high-voted troubleshooting thread, reboot resolves 90% of “marked for delete” cases without data loss. Test in a VM if paranoid.


Last Resort: Manual Registry Cleanup

sc delete bombed out? Export HKLM\SYSTEM\CurrentControlSet\Services first (backup!), then:

  1. Open regedit as admin.
  2. Navigate to HKLM\SYSTEM\CurrentControlSet\Services\YourServiceName.
  3. Right-click the key > Delete.

Reboot. Risky—wrong delete bricks services. Only if commands fail, as warned in this detailed guide.


Sources

  1. How do I uninstall a Windows service if the files do not exist anymore? — Step-by-step sc delete for orphaned services: https://stackoverflow.com/questions/197876/how-do-i-uninstall-a-windows-service-if-the-files-do-not-exist-anymore
  2. How to: Install and Uninstall Services — Official Microsoft guide on sc delete and InstallUtil /u: https://learn.microsoft.com/en-us/dotnet/framework/windows-services/how-to-install-and-uninstall-services
  3. How to force uninstillation of windows service? — Troubleshooting handles, MMC, and PID kills: https://stackoverflow.com/questions/225275/how-to-force-uninstallation-of-windows-service
  4. How to Uninstall a Service — Registry cleanup as fallback method: https://www.codetwo.com/kb/how-to-uninstall-a-service/

Conclusion

Bottom line: sc delete in elevated CMD uninstalls your orphaned .NET Windows Service reliably—no files, no regedit needed 99% of the time. Prep by stopping it and closing MMC, fall back to PowerShell if scripting, and reserve registry tweaks for extremes. You’ll have a clean services.msc in minutes; mark it done and move on.

Authors
Verified by moderation
Uninstall .NET Windows Service Without Files: sc delete