I created a Windows Service installer using WiX and included a custom action that called PowerShell to run a script. Unfortunately, I called the script with the wrong parameters and then the service would not uninstall. So, I tried a lot of different tricks and finally found a recommendation on the web to run the sc.exe command with the delete parameter. This was the only solution that worked, so I thought I’d share it here. I executed:
1 sc delete "My Service Name"
Note that to execute the same command from PowerShell, you must specify the full path to sc.exe because PowerShell has a default alias for sc assigning it to Set-Content. I executed it as follows:
1 C:\Windows\System32\sc.exe delete "My Service Name"
I hope this saves someone else some grief in the future.
This post was migrated from https://blogs.msdn.microsoft.com/rob/2012/06/07/deleting-windows-services-that-wont-uninstall/.