Batch to check if process exists

  • 8 months ago
Comment

ChatGPT
1 / 1

To check if a process exists using a Windows batch script, you can use the tasklist command. Here's how you can do it:

batch
@echo off
setlocal

set "processName=your_process_name.exe"

tasklist /FI "IMAGENAME eq %processName%" 2>NUL | find /I "%processName%" >NUL
if %errorlevel% equ 0 (
echo Process %processName% is running.
) else (
echo Process %processName% is not running.
)

endlocal

Replace your_process_name.exe with the name of the process you want to check. This batch script uses the tasklist command to list all running processes and then uses find to check if the specified process name is present in the list. If the process is found, the errorlevel will be set to 0; otherwise, it will be set to 1.

Save this code as a .bat file and run it from the command prompt. It will display whether the specified process is running or not.