Place this in a .bat of .cmd file
@echo off
if "%1"=="" goto instructions
if "%3"=="Start" goto start_Service
if "%3"=="Stop" goto do_bounce
:do_bounce
rem Query for service running and bail if not
sc \\%1 query %2 | find "RUNNING"
if errorlevel 1 goto end
rem Stop the service and loop checking for it to stop
sc \\%1 stop %2
goto check_stopped
:check_stopped
ping 127.0.0.1 -n 2 >NUL 2>NUL
sc \\%1 query %2 | find "STOPPED"
if errorlevel 1 goto check_stopped
GOTO END
:start_Service
rem Restart the service
sc \\%1 start %2
goto end
:instructions
ECHO "Usage is service.bat <server name> <service name> [Start:Stop]"
ECHO "YES it is case sensitive"
:end
Advertisement