How to make a Batch check Proccess

January 26, 2011 at 11:28:01
Specs: Windows 7, 12GHZ,12GB DDR5
How to make a Batch check Proccess If it is not running start the program,
If it is running then Exit, i tried this wich failed now im at a standstill...

tasklist /FI "IMAGENAME eq test.bat" /FO CSV > search.txt

FOR /F %%A IN (search.txt) DO IF %%~zA EQU 0 GOTO end

start test.bat

:end

del search.txt

hmm im completly stuck


See More: How to make a Batch check Proccess

Report •


#1
January 26, 2011 at 12:48:30
What is the name of the program or service you are looking for? Is it really "0"?

Report •

#2
January 26, 2011 at 14:34:56
Here is an example opening notepad if it is not already open...

@echo off
tasklist /FI "IMAGENAME eq notepad.exe"|Findstr "INFO: No tasks are running which match the specified criteria." >NUL
IF ERRORLEVEL 0 start notepad.exe
IF ERRORLEVEL 1 (
  echo Notepad is already running.
  pause
)

OOPs here is a tested one...

@echo off
tasklist /FI "IMAGENAME eq notepad.exe"|Find "No tasks"
IF %ERRORLEVEL% == 0 start notepad.exe


Report •

#3
January 26, 2011 at 16:09:55
Sometimes Tasklist outputs the info with "no tasks" to the error stream......

It can't hurt to mix the streams:

tasklist /FI "IMAGENAME eq notepad.exe" 2>&1 |Find "No tasks" >nul


Report •

Related Solutions


Ask Question