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.
Here's how I've worked it out:
The above will open Notepad if it is not already running.
Edit: Note that this won't find applications hidden from the tasklist. This will include any scheduled tasks running as a different user, as these are automatically hidden.
I use PV.exe from http://www.teamcti.com/pview/prcview.htm installed in Program Files\PV with a batch file like this:
I usually execute following command in cmd prompt to check if my program.exe is running or not:
You should check the parent process name, see The Code Project article about a .NET based solution**.
A non-programmatic way to check:
c:\windows\notepad.exe
)The same can be checked by getting the parent process name.
The suggestion of npocmaka to use QPROCESS instead of TASKLIST is great but, its answer is so big and complex that I feel obligated to post a quite simplified version of it which, I guess, will solve the problem of most non-advanced users:
The code above was tested in Windows 7, with a user with administrator rigths.