Re: More difficult question - how do I wait until another application closes?
- From: "Rick Rothstein" <rickNOSPAMnews@xxxxxxxxxxxxxxxxx>
- Date: Sun, 18 Jun 2006 11:54:04 -0400
Now I have a Shell command which runs a program EasyBMPtoAVI.exe in
another window (MS-DOS window). That thing typically takes 2 to 100
seconds to complete the run. After that I should delete a lot of files
I create in Visual Basic for EasyBMPtoAVI to process and combine.
How do I make VB watch for EasyBMPtoAVI to finish its task, after
which the code can continue with Kill Image*.bmp and inform me that
the AVI is ready? For the time being, I put a MsgBox command saying
MsgBox "Click OK after EasyBMPtoAVI has completed its task". So once I
click that, the code continues with deleting the myriad bmp's. It
would be nice to do it without the user's involvement, if the code for
that is not complicated.
MICROSOFT 'S OFFICIAL WAY
========================
See this link
http://support.microsoft.com/support/kb/articles/Q129/7/96.asp
Note: This method doesn't use Shell -- it uses CreateProcessA (and provides
example code).
FAST AND DIRTY METHOD
======================
Paste these lines in the (General)(Declarations) section of the form where
the Shell is being called (or remove the Private keywords and put them in a
BAS module if more than one form will use them):
Private Declare Function OpenProcess _
Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle _
Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject _
Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Call your Shell command in this form with the appropriate Shell arguments
placed in the parentheses:
PID = Shell( <<Put Shell Arguments Here>> )
And finally, paste the following IMMEDIATELY after the PID=Shell statement
above (making sure to handle the possible error where indicated; i.e. stop
the code from falling through to your other commands if the Shell failed):
If PID = 0 Then
'
'Handle Error, Shell Didn't Work
'
Else
hProcess = OpenProcess(&H100000, True, PID)
WaitForSingleObject hProcess, -1
CloseHandle hProcess
End If
Rick
.
- Follow-Ups:
- References:
- Prev by Date: More difficult question - how do I wait until another application closes?
- Next by Date: File opening closing and wriing in VBA
- Previous by thread: More difficult question - how do I wait until another application closes?
- Next by thread: Re: More difficult question - how do I wait until another application closes?
- Index(es):
Relevant Pages
|