Re: More difficult question - how do I wait until another application closes?



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.

































..





.



Relevant Pages

  • Re: can shell tell an exe to close
    ... How would I use Shell to close pgm.exe when it it running. ... For example, you could use FindWindow, EnumWindows, etc. to get the hWnd of the window. ... You can then close the window via numerous ways. ... Private Declare Function GetWindowThreadProcessId Lib "user32" (_ ...
    (microsoft.public.vb.winapi)
  • Re: task list
    ... Shell returns a process id you can use to identify the running process. ... Private Declare Function GetExitCodeProcess Lib "kernel32" (_ ... Public Function Process_Still_ActiveAs Boolean ... Dim lExitCode As Long ...
    (microsoft.public.vb.winapi)
  • [Full-disclosure] Reverse Shell Without Enabling Netcats "GAPING_SECURITY_HOLE"
    ... While the method below does not provide a "TRUE" interactive shell it ... get in the way of proper communication using this method. ... output of your commands in and run. ... On the attacker host open a terminal window that you want to enter in your ...
    (Full-Disclosure)
  • RE: Opening Access database
    ... Here's a Shell function method, but it will give you limited automation ... You can then control the application using Access objects and methods, ... maximizes the project window within the Access main window, ... then that app will receive the keystrokes. ...
    (microsoft.public.excel.programming)
  • Re: Custom shell window management
    ... there and change all window attributes to remove system buttons and system menu items ... Another quick and dirty workaround would be to handle WM_ACTIVATE event for your shell app window and, ... I'd recommend you to create your shell app with CreateWindowEx API with the WS_EX_NOACTIVATE ex-style set. ... that seem common to custom shell creation. ...
    (microsoft.public.windowsxp.embedded)