My Writings. My Thoughts.

Script de gestion d’un service en Batch

// août 3rd, 2009 // No Comments » // Non classé

:: Script pour simplier le demarrage et l'arret du service SRVC_XXX

@echo off

echo ----------------------------------------
echo !     SRVC_XXX service management     !
echo ---------------------------------------- 

net start | find "SRVC_XXX" >nul 2>nul
if /i "%errorlevel%"=="0" echo SRVC_XXX is running
if /i "%errorlevel%"=="1" echo SRVC_XXX is not running

:help
echo.
echo Type "start" to start the service
echo Type "stop" to stop the service
echo Type "exit" to quit this script
echo type "help" to get this help
echo.

:start
set /p _reponse="> "
if /i "%_reponse%"=="exit" goto end
if /i "%_reponse%"=="start" goto start_SRVC_XXX
if /i "%_reponse%"=="stop" goto stop_SRVC_XXX
if /i "%_reponse%"=="help" goto help
goto start

:check
net start | find "SRVC_XXX" >nul 2>nul
if /i "%errorlevel%"=="0" goto success
if /i "%errorlevel%"=="1" goto failure

:start_SRVC_XXX
net start "SRVC_XXX" >nul 2>nul
goto check

:stop_SRVC_XXX
net stop "SRVC_XXX" >nul 2>nul
goto check

:success
echo SRVC_XXX is running
echo.
goto start

:failure
echo SRVC_XXX is not running
echo.
goto start

:end
echo Bye.
echo.

set _string=
set _result=