57705Views8Replies
Check if a process is running from a batch file?
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?
**I thought I was close with this, but I can't get it to work.**
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.
Redirect to NUL after FIND.
Try this
:
@echo off
tasklist /nh /fi "imagename eq wmplayer.exe" | find /i "wmplayer.exe" >nul && (
echo Windows Media Player is running
) || (
echo Windows Media Player is not running
)
pause>nul
Select as Best AnswerUndo Best Answer
Man, you are a genius! THANK YOU SO MUCH! How did you figure it out?
Select as Best AnswerUndo Best Answer
Hi I'm trying below program, if the exe is running another instance of same exe I don't want to run..so waiting till it completes..
Not sure where the problem in the below code it is not working "The syntax of the command is incorrect." error
*********************************************************
@echo OFF
:LOOP
tasklist /fi "IMAGENAME eq Test.exe" | find /i "Test.exe"
if errorlevel
(
SLEEP 5
GOTO LOOP
)
else
(
echo print
start "" "C:\Users\Desktop\Test.exe"
)
**************************************************************
kindly suggest
Select as Best AnswerUndo Best Answer
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.
Select as Best AnswerUndo Best Answer
Not as tidy as g-one's but you can use for and test for the message "INFO: No tasks are running which match the specified criteria."...
@echo off
for /f "usebackq" %%Z in (`tasklist /nh /fi "imagename eq wmplayer.exe"`) do if %%Z==INFO: goto processnotrunning
echo Windows Media Player is running
exit
:processnotrunning
echo Windows Media Player is not running
Select as Best AnswerUndo Best Answer
Can you use wildcards using this? like to see if ANY executable process is running? lol]
like this:
for /f "usebackq" %%Z in (`tasklist /nh /fi "imagename eq *.exe"`) do if %%Z==INFO:
Select as Best AnswerUndo Best Answer
REM ---Copy all of this text into a notepad and save it as a batch file
REM ---to see if a program is running
@echo off
:start
set /p runningprocess=Enter a program name to see if it is running:
rem ---- 1: all one line ----
tasklist /FI "IMAGENAME eq %runningprocess%" | find /I "%runningprocess%" > nul
rem ---- 1: end of line
IF %ERRORLEVEL% equ 0 ECHO Notepad is running
IF %ERRORLEVEL% equ 1 ECHO Notepad is not running
pause>nul
goto start
Select as Best AnswerUndo Best Answer
Just because I can, here's another answer.
Link.
Up there is a link to a dostips function called IsServiceRunning.
Hope it helps.
Select as Best AnswerUndo Best Answer