General Question

XOIIO's avatar

Check if a process is running from a batch file?

Asked by XOIIO (18328points) January 1st, 2011

I need a command simmilar to “IF EXIST” to check if a process, such as wmplayer.exe is running. Something like this.

if exist wmplayer.exe (echo proccess running) else (echo proccess not running

Can you think of anything?

Observing members: 0 Composing members: 0

2 Answers

XOIIO's avatar

Well, I have this bit of code

IF ”%notepad.exe%”==”” (echo The process is not running) ELSE (echo the program is running)

With it set up like this it always says the process is not running

IF ”%notepad.exe”==”” (echo The process is not running) ELSE (echo the program is running)

With this it aways it running.

Any ideas on how to get it to work? I know I’m really close.

XOIIO's avatar

I got this to work.

@echo off
tasklist /FI “IMAGENAME eq wmplayer.exe” | find /I “wmplayer.exe”
IF ERRORLEVEL 2 ECHO Windows Media Player is running
IF ERRORLEVEL 1 ECHO Windows Media Player is not running
pause>nul

But it shows this when the process is running.

wmplayer.exe 13788 Console 1 20,300 K

I tried adding >nul to the tasklist line but then it didn’t show anything when the process was running.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther