首页 > 解决方案 > 判断进程是否正在运行的批处理脚本

问题描述

我对批处理文件非常陌生,并且正在尝试创建一个脚本来检查进程是否正在运行并在进程是否运行时发出警报。这是我从谷歌得到的,但没有按照我想要的方式工作。

tasklist /FI "IMAGENAME eq example.exe" 2>NUL | find /I /N "example.exe">NUL if "%ERRORLEVEL%"=="0" echo Program is running

标签: batch-file

解决方案


您正试图使其复杂化。将以下内容复制到批处理文件中。也使用 findstr 代替。

tasklist /fi "imagename eq example.exe" | findstr /i "example.exe" >nul
If %errorlevel%==0 echo example.exe running.
If %errorlevel%==1 echo example.exe Not running.

推荐阅读