2

How can I tell if a specific process is running using a batch file?

For example, How can I tell if notepad.exe is running?

0

3 Answers 3

4

Consider the following proposal (run in your batch file):

tasklist | findstr /R ^notepad.exe

Simple, but works!

tasklist /?

Will show you a lot of great options for filtering and managing your output.

findstr /?

Will also show you a great set of options to search and filter the output of tasklist

I hope this helps.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you! Great answer, just one problem: the execution time for this takes 10+ seconds! Is there and way to do this in a shorter time?
Do you have a lot of processes running? It's running very fast for me...
Yes I tend to have quite a few processes running at a time.
That might be the cause. I've seen cases where tasklist was slow. I don't have a solution for this. Sorry...
3

Powershell has an in-built function. Get-Process Get-Process will tell you about all the processes. If you wish to filter with a particular one then use :

Get-Process|?{$_.Name -eq 'Notepad'}

Screenshots are for reference:

Type Powershell in cmd prompt:

enter image description here

Run the above query. If the notepad is running. It will show you: enter image description here

Hope it helps...

1 Comment

type first powershell in cmd prompt. Then run the above command what I pasted. If you directly using cmd prompt then the pipeline wont work because the values which are passed after the pipe as inputs are powershell cmdlets. Thats why it is not returning anything.
2

You can do something like this in batch file :

This one is inspired from Check if a process is running or not?

@echo off
Title Check for running process . . .
mode con cols=50 lines=3
set "MyProcess=notepad.exe"
set delay=5
:Main
cls
Tasklist /FI "IMAGENAME eq %MyProcess%" | find /I "%MyProcess%">nul && (
    echo( & Color 9A
    echo         PROCESS "%MyProcess%" IS RUNNING !
)||(
    echo( & Color 4C
    echo        PROCESS "%MyProcess%" IS NOT RUNNING !
)
Timeout /T %delay% /nobreak>nul
Goto Main

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.