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?

cascading-style
  • 488
  • 9
  • 23

3 Answers3

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.

Eldad Assis
  • 10,464
  • 11
  • 52
  • 78
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...

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
  • 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. – Ranadip Dutta Dec 11 '16 at 06:59
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
Hackoo
  • 18,337
  • 3
  • 40
  • 70