Batch help, i'm rusty

k1pp3r

[H]F Junkie
Joined
Jun 16, 2004
Messages
8,339
I have the following code, but i'm so rusty on batch files i cant get the darn thing working.

Sometimes it reports correct, others it doesn't


Code:
@Echo off
if exist tasklist /fi "IMAGENAME eq psa.exe" errorlevel 1
if errorlevel=1 (Goto :running) Else (goto :norun)

:running
echo Program is running
set errorlevel=0
Goto :eof

:norun
Echo Program is NOT running
set errorlevel=0
Goto :eof

Any help is great, the objective is to see if a task is running, if it is, good exit. If not it will call that program.
 
Better way of doing it:

Code:
@Echo off
tasklist | find /I "psa.exe"
if errorlevel=1 goto norun 

:running
echo Program is running
Goto :eof

:norun
Echo Program is NOT running
psa.exe
Goto :eof
 
Better way of doing it:

Code:
@Echo off
tasklist | find /I "psa.exe"
if errorlevel=1 goto norun 

:running
echo Program is running
Goto :eof

:norun
Echo Program is NOT running
psa.exe
Goto :eof

I will give this a try, thanks!
 
If exists looks for a file. REDYOUCH's solution should work, as it grabs the entire task list and then searches for the psa.exe string within the result.
 
Back
Top