Link to home
Start Free TrialLog in
Avatar of BenClark
BenClark

asked on

Is it still running???

I have one application, 32 bit, which uses ShellExecute to launch other applications, 16 or 32 bit.
How can the launching application tell when the launched application is finished.
The handle returned from ShellExecute doesn't seem to help.
Avatar of tflai
tflai

Try ShellExecuteEx() and WaitForSingleObject() on the process handle.
Avatar of BenClark

ASKER

That does work but I need to do other work while the second application is running. In fact, the first application will be launching one or MORE applications at the same time.
Some apps could be 16 bits and some could be 32 bits.
I need a way of getting a list of running apps so the calling application can check every so often.

If you're using Windows 95, you can use Process32Fist() and Process32Next().

If you're using Windows NT, you have to walk down the performance registry key at

  HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\currentversion\perflib

to get the list of running tasks.
Could you give me a little more info on the NT route.
I got the Win95 route. Thanks
I increased the points for all your help.
Thanks
The earlier answer:

Try ShellExecuteEx() and WaitForSingleObject() on the process handle.

will work but if you need to do other things.  Call ShellExecuteEx() in a thread that can then wait on the process with WaitForSingleObject()
The main language I am using will not support threads.
I need a list.
Something like the windows task list.

Thanks
You can still use WaitForSingleObject() while you're doing other stuff: just supply a timeout of zero milliseconds.  If the call returns successfully, then the application is no longer running. If the call returns with a timeout, the application is still running.

You can do this in response to a timer, if you want.

.B ekiM
What do you mean "does not support threads"?  What language is that?  What's wrong with calling BeginThread() ?
The language is PowerBuilder 6.
It will not handle Enums, Callbacks or Threads.
Even though I can call BeginThread(), I can't get the
function address from PowerBuilder to pass to BeginThread().

Is there a reason you rejected my answer?

.B ekiM

It is still not what I need.
I want to do the equivelant of
FindFirstProgram()
FindNextProgram()

I never used PowerBuilder but I think that's possible to call a
DLL, so you can write a DLL which inspects Internal Process Database (using Process32First and so on from Toolhelp DLL).
You can pass a pointer variable to your DLL which on return
contents address of a list of processes or threads.
I'm currently using a DLL like this written in Visual C++.
If this what's your looking for, then I can post the code.
But the most important thing is that PowerBuilder can call DLL's written in C.
That will work for Win95 but what about NT?

Mike B.'s answer is good--just keep your own list of processes that you've started.  Whenever you want to know which of those processes is done, call WaitForSingleObject () on each of their handles.
Then if Mike will resubmit his answer I will give him credit.
ASKER CERTIFIED SOLUTION
Avatar of cessi0g
cessi0g

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you've got the handle to the process you created (which ShellExecuteEx() gives you), you can use WaitForSingleObject() to see if the process has terminated or not.

If you don't know the handle, you'll have to screw around with the TOOLHELP routines. If you're using WinNT 5.0 or Win95 or Win98, TOOLHELP's the way to go. If you're using anything else, you'll have to find another way--like walking through the performance data. And that's a real chore.

It's trivial to keep the handle to the process you've started, and use it later. That'll avoid all the crazy work you'd have to do with TOOLHELP or with the performance registry entries.

.B ekiM

Thanks