I would like to know how to check if a service is running using a batch file
e.g.
if xxxx service is running go to start stage2.bat else go to echo Service not running
Any help would be appreciated
Thanks
Similar to How to check if a process is running via a batch script
EDIT:
From the post, with an added else statement:
tasklist /FI "IMAGENAME eq myapp.exe" 2>NUL | find /I /N "myapp.exe">NUL
if "%ERRORLEVEL%"=="0" (
call stage2.bat
) else (
echo Program is not running
)
For a service:
sc query "ServiceName" | find "RUNNING"
if "%ERRORLEVEL%"=="0" (
call stage2.bat
) else (
echo Program is not running
)
read this article http://support.microsoft.com/kb/251192 and see SC /?
then try
SC QUERY
EDIT: to automate the check, pipe the result to FIND and look for RUNNING
SC QUERY %1 | FIND "STATE" | FIND "RUNNING" >nul
IF ERRORLEVEL 1 (echo NOT RUNNING ) ELSE (echo RUNNING)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With