Click here to Skip to main content
15,885,278 members
Articles / DevOps
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
24 Aug 2018CPOL2 min read 10.4K   176   5  
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.

Image 1

The (2) folder has the scripts for you to try.

Image 2

 

Given below are the steps to test.

Step 1

Right click "00_InstallMyService.bat", and make sure to pick "Run as administrator" option.

Image 3

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.

Image 4

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Canada Canada
Yet another jack-of-all-trades programmer?


Comments and Discussions

 
-- There are no messages in this forum --