Is there a batch command that will check if a program is running and shutdown the PC if it isn't?
Thats Possible, example looking for running Internet explorer:
@echo off
tasklist /fi "imagename eq iexplore.exe" | find /I "iexplore.exe" > nul
if errorlevel 1 goto SHUTDOWN
echo IE is already running
goto DONE
:SHUTDOWN
shutdown -s -f -t 0
goto DONE
:DONE
exit
EDIT
if you want to Loop this command use this:
@echo off
:loop
tasklist /fi "imagename eq iexplore.exe" | find /I "iexplore.exe" > nul
if errorlevel 1 goto SHUTDOWN
echo IE is already running
goto DONE
:SHUTDOWN
shutdown -s -f -t 0
goto DONE
:DONE
REM wait 5 sec
ping 127.0.0.1 -n 2 -w 5000 > NUL
goto loop
Just for a one liner
for /l %%# in (1 0 2) do (tasklist|find /i "program.exe">nul ||(shutdown -s -f -t 0 & exit /b))
Create a loop starting in 1 until 2 with a step of 0, check if program.exe in tasklist output. If it fails run shutdown and exit.
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