Is an EXE or Process Running?

My Clarion emailtimer app relies on another app called “scanner.exe” to be running. It’s a vb.net application, and I have set it so that only one instance is running. I could just try executing “scanner.exe” on a regular basis, but that’s a horrible solution, and in other examples I would end up with hundreds of copies of the same app running until windows crashes.

In vb.net there is a function called GetProcessesByName(“scanner.exe”)
Member of System.Diagnostics.Process
In the windows32 PSAPI there are functions to enumerate the running processes. I have looked at the winapi by @Mike_Duglas but can’t find anything that matches.

Any suggestions?

winapi - How can I get a process handle by its name in C++? - Stack Overflow

You can use TToolHelp class from my winapi, all needed methods are in there.

1 Like

In LibSrc \ WinExt.Clw / .INC you’ll find:

WindowExtenderClass.IsInstanceRunning PROCEDURE(<STRING processExeName>)

It may be all you need, but it has the code to call Process32First() and Process32Next() that should help you write your own.

See Also:

2 Likes

I’m missing something really obvious here: what do I need to do to get the IsInstanceRunning method to work? If I just add this code to the main frame’s timer event I get errors complaining about no matching prototype. So clearly I haven’t included missing bits.

  !// Timer event
  if IsInstanceRunning('scanner.exe') then
      message('scanner.exe')
  end

I have searched in vain through the Clarion documentation and PDFs and found a cryptic reference to the WindowExtender class, but nothing further.

I have included the line INCLUDE('winext.inc'),ONCE in the “After Global INCLUDEs” global embed, but I’m not sure if that’s correct, and I don’t know whether to include winext.clw anywhere.

I’m missing something basic.

1 Like

IsInstanceRunning is a method of a class, not a standalone procedure.
You need to declare an instance of WindowExtenderClass and then call the IsInstanceRunning for that class.

1 Like

Hi,
Also a similar need here. This post to INCLUDE(‘winext.inc’),ONCE gave me hope…

After instantiating the class, the app compiles.

WE WindowExtenderClass

IF WE.IsInstanceRunning('Notepad.exe')
    Message('Notepad.exe APP is still running')
.

But it always return FALSE.
Tried naming a few other apps as well, still FALSE.

What am i missing?

Haven’t checked, just a thought: WindowExtenderClass.IsInstanceRunning() probably does not work with 64 bit processes.

Yeah it doesn’t work if I try to check if clarion.exe is running either?

Not an answer to your question but there are two addons available here…

…to check if an executable is running - search for ‘running’ on the page.

Vice Sorenson’s ABC Free templates, available at the same page and also here…

https://www.authord.com/products/Clarion/

…have functions to enumerate running applications.

There is also this, I don’t have a record of who wrote it?
procrun.zip (68.9 KB)

1 Like

Hi Geoff,

I also tried EnumWindows from ABC Free. But executing the code seemed to freeze the 3 procedure-app.
I do recall @anon77170705 made reference in this post to Process32First and Process32Next

How to access the Win32 library functions is still a new area for me.

Yiippee!! your example in “procrun.zip” worked first time. :clap: Simple and easy to implement.

Thank you very much for sharing.

1 Like

Seems WindowExtenderClass.IsInstanceRunning just doesn’t work in most cases, If a requested process is actually running, _Process32First or _Process32Next finds it successfully but a subsequent comparision “IF th32sessionsID = currentSID” usually fails because currentSID has default value 0, and th32sessionsID <> 0.

Tested on C11.1.13815.

Glad it’s working!

And, just to reclarify, it’s not my code and I don’t know who wrote it.