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.

  1. I was trying to do a similar thing but may be an extension of this. I am not a software programmer so have limited knowledge. I have a server running windows 2008 Std. Since about couple of months, the server seems to be having an issue and it becomes unresponsive. I checked the Events on the server but I could not find anything that will point out to why it hanged. I suspect two programs (1.File Backup application and 2. A accounting application) to be at fault but unable to confirm it. Do you think I can use this script to identify the problem causing program? Thanks!

  2. This little snippet of code will not accomplish what you are looking for. However, to start with, you can actaully see what program is using more memory/cpu through the taskmanager. Then probably you might get a fair idea on what’s causing the issue.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>