Kill A Windows Service Script

I created this little tiny script for readability’s sake. I could easily have folded it into one giant batch file, but I like to document what I’m doing, and leave behind a well-polished tool for the people I work with.

This script takes the name of the service as it’s one argument and then issues a polite “stop” command via the sc.exe program. The server is a global variable available from the calling batch file, which is outlined here.




KillService.bat

:: -----------------------------------------------------------
:: This script relies on the global variables of the script 
:: that called it.  It issues a polite "stop" command to the 
:: service and returns control to the calling script.
:: 
:: Thom Rosario
:: 7.31.2013 -- v1.0
:: -----------------------------------------------------------

@echo off
set srvc=%~1

echo - - = = STOPPING %srvr% = = - -
sc.exe \\%srvr% stop %srvc%
timeout /t 3
echo %srvc% stopped on %srvr%
goto :EOF


Leave a Reply

Your email address will not be published. Required fields are marked *