2013-10-29 48 views

回答

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 
+0

'set SR =%〜d0%〜p0'是怎么回事? –

+0

批处理的当前路径;) – Oli

+0

我在Windows 8中编写它,但将在Windows 7上执行它。现在总是说IE正在运行。 8是不同的? – user2932330

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 
1

只需要一个衬里

for /l %%# in (1 0 2) do (tasklist|find /i "program.exe">nul ||(shutdown -s -f -t 0 & exit /b)) 

创建1开始一个循环,直到2为0的步骤,检查是否在的Program.exe输出任务列表。如果失败则运行关机并退出。

相关问题