Detecting when a 'shell'ed application has closed 
Author Message
 Detecting when a 'shell'ed application has closed

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.



Sat, 27 Nov 1999 03:00:00 GMT  
 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.
: >
: >
:



Sun, 28 Nov 1999 03:00:00 GMT  
 Detecting when a 'shell'ed application has closed

Quote:

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

If it os OK for your app to block until the called app finishes, look at
the CreateProcess and WaitForSingleObject APIs.  This way you can wait for
Windows to tell you when the app has closed rahter than polling it
constantly.

--
Mark Wagoner




Sun, 28 Nov 1999 03:00:00 GMT  
 Detecting when a 'shell'ed application has closed



Quote:
> 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.

I got an overflow error when I tried that.  I think I'm right in
saying that GetModuleUsage only works for 16 bit stuff?

Steve Hanvy



Mon, 29 Nov 1999 03:00:00 GMT  
 Detecting when a 'shell'ed application has closed

Yes, again, take a look at the KB article Mathias Schiffer
posted about.



Quote:


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

> I got an overflow error when I tried that.  I think I'm right
in
> saying that GetModuleUsage only works for 16 bit stuff?

> Steve Hanvy



Mon, 29 Nov 1999 03:00:00 GMT  
 Detecting when a 'shell'ed application has closed

Quote:



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

>I got an overflow error when I tried that.  I think I'm right in
>saying that GetModuleUsage only works for 16 bit stuff?

>Steve Hanvy

I had this problem too.  I was porting an application to Win95, and my support
DLL which calls GetModuleUsage had to be changed.  I now watch for the process
ID of the program I shelled, and wait for it to exit/disappear.

. Jason Badry

--
   PP     PR
  APPRO CHPRJ   Jason Badry, BSc.           The APPROACH Project
  APPROACHPRJ   System Administrator        EDC 1072, 8440 - 112 St
   PPROACHPR                                Edmonton, Alberta  T6G 2B7
    PROACHP     Tel. (403) 492-5561
     ROACH      Fax. (403) 492-3326

       A        http://www.uah.ualberta.ca/jbadry



Tue, 30 Nov 1999 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Waiting for 'SHELL'ed application to finish

2. FindWindow and Shell'ed app id

3. Cancelling a Shell()ed app that's inactive

4. Use Win95 API in VB4 to Wait for a Shell'ed Program to Complete

5. Exiting applications with 'Close' button

6. Closing an 'unknown' application with VB5

7. Close from Control Box Doesn't Close Application

8. Unloading a 'Dim'ed Form

9. Launch, then close a SHELL'd app?

10. Why windows won't close after shell process

11. closing dos app's window after shell

12. Access won't close after 'application.close'

 

 
Powered by phpBB® Forum Software