Re: More difficult question - how do I wait until another application closes?
- From: new.user@xxxxxxxxxx (new user)
- Date: 19 Jun 2006 12:01:22 +0300
Comments/question below (to avoid top posting)
In article <Ru-dnQDpTN2B6gjZnZ2dneKdnZydnZ2d@xxxxxxxxxxx>,
Rick Rothstein <rickNOSPAMnews@xxxxxxxxxxxxxxxxx> wrote:
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
That was a good answer. I think I have found a simpler way. Please let
me know if there is something wrong about the following (is it bad
practice for some reason?).
X = Shell("calc.exe", 1)
AppActivate "Calculator"
On Error GoTo Closed
While Now > 0
DoEvents
AppActivate "Calculator"
Wend
Exit Sub
Closed:
MsgBox "App closed"
Exit Sub
When I manually close down the calculator window, I get the message
box.
..
.
- Follow-Ups:
- Re: More difficult question - how do I wait until another application closes?
- From: Steve Gerrard
- Re: More difficult question - how do I wait until another application closes?
- References:
- Prev by Date: FileListBox and directories with more than 32,768 files!
- Next by Date: Re: More difficult question - how do I wait until another application closes?
- Previous by thread: Re: 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
|