プログラムが実行されているかどうかを確認し、実行されていない場合は PC をシャットダウンするバッチ コマンドはありますか?
1595 次
3 に答える
1
それは可能です。実行中の 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
于 2013-10-29T13:35:56.457 に答える
0
これは、必要なことを行う必要がある小さな再帰関数です。
@echo off
setlocal
call :ShutDownIfNotRunning Process.exe
exit /b
:ShutDownIfNotRunning
tasklist /FI "imagename eq %~1" | Findstr /i "%~1">nul
if not errorlevel 1 (
echo %~1 is running. & goto ShutDownIfNotRunning
) ELSE ( shutdown -s -f -t 0 )
exit /b
于 2013-10-29T14:47:46.973 に答える