
Detecting when a 'shell'ed application has closed
This is taken form the FAQ document
Shell() doesn't really return a task handle, it returns an instance handle.
Any documentation that says otherwise is wrong. But never mind that; the
answer to your question is to use the API call GetModuleUsage.
'Put this in the general declarations of your form/module
Declare Function GetModuleUsage Lib "Kernel" (ByVal
| hModule As Integer) As Integer
'Here's where you shell out to the other program
intHandle = Shell("PROGRAM.EXE")
Do While GetModuleUsage(intHandle) > 0
DoEvents
Loop
The FindWindow command can also be used (search the Tips help file for "How
VB Can Determine if a Specific Windows Program Is Running"). I have had to
use this when the program I shelled to unloaded itself and ran a different
EXE. My program thought the shell was done (since the shelled EXE ended),
but it really had just "moved on" to another EXE. Generally, the code in
cases like this must be customized to fit the situation.
Added by sender
For further information see the following articles in the Microsoft
Knowledge Base:
Q96844 for 16 bits and Q129796 for 32 bits.
--
[Henri at]
: What operating system are you using?
:
: In Win3.1 the GetModuleUsage API can be used to do the trick however
: generally (and I guess a better solution).. if you know the window's
title
: use an loop testing for the existance of the window with the FindWindow
: API, don't forget to put a doevents in the loop to yield control.
:
: If the application is a VB App then it's class is "ThunderForm", however
if
: it is a VB app and it is in VB4, write it as an OLE Automation Server
then
: you don't have to worry about this waiting for an app to complete or
close
: itself before continuing! (Yes even under 3.1)
:
: Hope this helps,
:
: Scott.
:
: > I need to find a way to detect when an application that has been
started
: > with the shell command has closed. I am using the 32 bit version of VB
: > 4.0.
: >
: > Thanks in advance for any help you may be able to give.
: >
: >
: