How to check if a process is running via a batch script

Matt Lacey picture Matt Lacey · Oct 2, 2008 · Viewed 616.7k times · Source

How can I check if an application is running from a batch (well cmd) file?

I need to not launch another instance if a program is already running. (I can't change the app to make it single instance only.)

Also the application could be running as any user.

Answer

Chaosmaster picture Chaosmaster · Aug 25, 2009

Another possibility I came up with, inspired by using grep, is:

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

It doesn't need to save an extra file, so I prefer this method.