Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

2 Options to Remove a Windows Service (and a Dummy do-nothing Windows Service for You to Play With)

0.00/5 (No votes)
24 Aug 2018 2  
How to remove Windows service from Service List (not just stop/disable it, but to delete it from the list totally)

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: 

  1. c:\temp\ServiceTest
  2. 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:

Hope this helps!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here