popunder new

https://www.blogger.com/blog/posts/1739890295310631346

Saturday, September 3, 2011

Batch file to start or stop a service depending on its current state

This batch file will start or stop a service depending on its current state.
Just replace yourservice on line 5 and 16 with the name of the service you want  to stop or start.
 @ECHO OFF  
REM Checking Service state
REM replace yourservice below with the name of the service
net start yourservice 2>nul
if errorlevel 2 goto AlreadyRunning
if errorlevel 1 goto Error
REM Service started
GOTO ContinueWithBatch
:AlreadyRunning
REM Service is already running
REM replace yourservice below with the name of the service
net stop yourservice
GOTO ContinueWithBatch
:Error
REM Service failed to start
GOTO ContinueWithBatch
:ContinueWithBatch

No comments:

Post a Comment