Consider a situation where you had to execute a job depending on whether another/same program is running. To solve this problem, we take the help of tasklist,find commands. Here is the code which gives us that information, save it as a batch file and tweak it to your needs:
In this example, we are checking for imagename/process chrome.exe
1 2 3 4 5 6 7 8 9 10 11
@echo off REM use tasklist to get the entire list of processes REM then using Find to see our program is running or not tasklist /FI "imagename eq chrome.exe" | find /C /I "chrome.exe" > nul if errorlevel 1 goto notfound echo process found goto endfind :notfound echo process notfound :endfind echo End of Program
In the above code all we do is use tasklist command with imagename filter to get a list of processes, then use find to get the errorlevel. Most programs generate an errorlevel of 0 if the program or command executed properly and error level 1 and above indicates that the program did not execute properly.