gpt4 book ai didi

batch-file - 批处理 : Shutdown PC if a Program isn't Running?

转载 作者:行者123 更新时间:2023-12-03 23:46:56 25 4
gpt4 key购买 nike

是否有一个批处理命令可以检查程序是否正在运行并在没有运行时关闭 PC?

最佳答案

这是可能的,例如寻找正在运行的 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

编辑

如果你想循环这个命令使用这个:

@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

关于batch-file - 批处理 : Shutdown PC if a Program isn't Running?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19659703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com