Quantcast
Channel: Byte Miner » admin
Viewing all articles
Browse latest Browse all 12

Batch script to monitor Windows Service

$
0
0

@echo off

FOR /F "tokens=2 delims= " %%i IN ('"wmic.exe SERVICE GET Name, State" ^| findstr /I Stopped ^| findstr /I SERVICENAME') DO if %%i==Stopped goto :stop
FOR /F "tokens=2 delims= " %%i IN ('"wmic.exe SERVICE GET Name, State" ^| findstr /I Running ^| findstr /I SERVICENAME') DO if %%i==Running goto :end

:stop
echo %Date%, %Time%, SERVICENAME service has stopped. >> E:\SERVICENAME_Status.log

:end

Replace SERVICENAME with the service name that you are interested to monitor.

At the end of that script, you can potentially call another script that sends an email or an alert to whatever event management system you use.

The post Batch script to monitor Windows Service appeared first on Byte Miner.


Viewing all articles
Browse latest Browse all 12

Trending Articles