Introduction
Two options to totally remove a Windows service from service list:
InstallUtil.exe /u [FullPath\ServiceName.exe]
SC delete [ServiceName]
I prefer the "SC
" way. It's neater, and really delete a service even if an old [ServiceName.exe]
somehow is broken and InstallUtil.exe /u
doesn't help in the case. I actually experienced the case.
Using the Code
To try my code example, make sure you create the same folder/path as illustrated.
Create two folders for test:
- c:\temp\ServiceTest
- c:\temp\ServiceTestInstaller
The (1) folder has a dummy service (do-nothing) to be installed/uninstalled.
The (2) folder has the scripts for you to try.
Given below are the steps to test.
Step 1
Right click "00_InstallMyService.bat", and make sure to pick "Run as administrator" option.
This should install the dummy service like below:
I red-marked several things for your attention: Executable EXE file name, Service name, Display name, Description are four different properties of a given service.
Later in the scripts, you will see that the EXE name and service name really matter.
Step 2
Right click "01_UnInstallMyService.bat", and make sure to pick "Run as administrator" option. Once it's done, go back to service list, you can see the service is totally gone.
All it does is this:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe" /u "C:\temp\ServiceTest\MyServiceAbc.exe"
pause
Step 3
Repeat step 1 to Install the service again.
Step 4
Right click "02_UnInstallMyService.bat", and make sure to pick "Run as administrator" option. Once it's done, go back to service list, you can see the service is totally gone.
All it does is this:
SC delete MyServiceName
pause
Points of Interest
The above codes are tested in Windows 10 and Windows 2008 R2 environments.
Nothing is really fancy here, but it's always good to know your options.
I attach all the codes as well:
- The dummy service code (It's done in VS 2013)
- Test script (very simple)
Hope this helps!