Page 1 of 1

How to determine if a specific process is running?

Posted: 10 Jun 2011 20:02
by Huidong
Is there a way (via scripting of course) to check if a specified process is running, w/o using third-party programs (I mean programs not built in Windows)? And return 1 if it is running, 0 else?
Thanks!

Re: How to determine if a specific process is running?

Posted: 10 Jun 2011 20:08
by nas8e9
Huidong wrote:Is there a way (via scripting of course) to check if a specified process is running, w/o using third-party programs (I mean programs not built in Windows)? And return 1 if it is running, 0 else?
Thanks!
This StackOverflow thread seems promising?

Re: How to determine if a specific process is running?

Posted: 10 Jun 2011 20:53
by Huidong
Thanks.
So far I have

Code: Select all

run "cmd /k tasklist /fi ""Imagename eq notepad.exe"" | find ""notepad.exe""", "C:\";
which works OK, but how to let it return an errorlevel value? I know if found, errorlevel==0, if not found, errorlevel==1
How to get the value after executing the run command?

Re: How to determine if a specific process is running?

Posted: 10 Jun 2011 21:33
by nas8e9
Huidong wrote:Thanks.
So far I have

Code: Select all

run "cmd /k tasklist /fi ""Imagename eq notepad.exe"" | find ""notepad.exe""", "C:\";
which works OK, but how to let it return an errorlevel value? I know if found, errorlevel==0, if not found, errorlevel==1
How to get the value after executing the run command?
It's getting really kludgy, but I'd have the batch file write a result code to a temporary text file and have XYplorer read and then delete that file.

Re: How to determine if a specific process is running?

Posted: 10 Jun 2011 21:44
by Huidong
That's not the major issue to me. Could you write the %errorlevel% value to a file? I can do echo %errorlevel% after find, and get the right value. But how to output that value to xy?

Re: How to determine if a specific process is running?

Posted: 10 Jun 2011 22:18
by nas8e9
Huidong wrote:That's not the major issue to me. Could you write the %errorlevel% value to a file? I can do echo %errorlevel% after find, and get the right value. But how to output that value to xy?

Code: Select all

echo %errorlevel% > %Temp%\Status.txt
I learnt about this back when I had to fend off dinosaurs so I'm not quite sure what the theory behind it is, but Google thinks the ">" character denotes a redirect.

In general, this stuff is very easy to find with Google (as alluded to earlier, this isn't exactly new/unknown territory... :)).