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

2011/09/03 | By | Reply More

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

Tags:

Category: Scripts

Leave a Reply

You must be logged in to post a comment.

YouTube Subscribe

Archives

Loading