How to Remove a Windows Service Registration

Prefer the application's supported uninstaller because it can remove related files and configuration as well as the service. sc.exe delete removes the service registration. It is not a complete product uninstall.

Identify the exact service

Use the service name, which can differ from the display name shown in Services. In elevated Windows PowerShell:

PowerShell
$serviceName = 'ExampleWorker'
Get-Service -Name $serviceName -ErrorAction Stop |
    Format-List Name, DisplayName, Status, DependentServices
sc.exe qc $serviceName

Replace ExampleWorker with the intended application service. Verify its executable path and dependencies before proceeding. Save the configuration if rollback may be required. Recreating a service from just its name and executable can omit important settings.

Remove the confirmed registration

If the owning product has no applicable uninstaller and direct removal is intended:

PowerShell
Stop-Service -Name $serviceName -ErrorAction Stop
(Get-Service -Name $serviceName).WaitForStatus('Stopped', [TimeSpan]::FromSeconds(30))
sc.exe delete $serviceName
if ($LASTEXITCODE -ne 0) { throw 'Service deletion was not accepted.' }
sc.exe query $serviceName

After completed deletion, sc.exe query reports that the named service does not exist. If another process still holds a service handle, Windows can mark it for deletion instead. Close the relevant management tool and let outstanding handles close before treating a reboot as necessary.

Match the removal tool to the installer

InstallUtil.exe /u applies to .NET Framework assemblies that were installed using compatible installer components. It is not a universal command for every modern .NET worker service. Use the correct runtime/architecture tool and the product's installation instructions when that path is appropriate.

Do not delete the executable or its data directory before the service identity and uninstall method are confirmed. Deleting the service registration leaves application data, scheduled tasks and firewall rules in place. Review the product-specific uninstall instructions for those. Verify the intended service is absent and that neighboring services still operate.

References

sc delete
Reference article for the sc delete command, which deletes a service subkey from the registry.
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/sc-delete
sc delete
Installutil.exe (Installer Tool) - .NET Framework
Use Installutil.exe, the Installer Tool. This tool lets you install or uninstall server resources by executing the installer components in specified assemblies.
https://learn.microsoft.com/en-us/dotnet/framework/tools/installutil-exe-installer-tool
Installutil.exe

Author: Herman Schoenfeld