How to determine if a specific process is running?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Huidong
Posts: 213
Joined: 18 May 2011 21:55

How to determine if a specific process is running?

Post 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!

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

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

Post 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?

Huidong
Posts: 213
Joined: 18 May 2011 21:55

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

Post 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?

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

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

Post 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.

Huidong
Posts: 213
Joined: 18 May 2011 21:55

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

Post 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?

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

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

Post 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... :)).

Post Reply