When I shell an app, how can I tell when it's completed?
Thanks in advance
Printable View
When I shell an app, how can I tell when it's completed?
Thanks in advance
Code:this is the code for trythis.exe
Private Sub Form_Load()
Dim x As Integer, y As Integer
Randomize
For x = 1 To 4000
y = x * Int(Rnd * 10) + 1
Next x
Unload Me
End Sub
'this is the code for Project1
Private Sub Command1_Click()
Shell ("C:\myApp.exe")
DoEvents
MsgBox "Done"
End Sub
You know.. I am shelling a DOS prog... (not my prog) to uncompress a set of files... I have no know way of knowing
when the uncompress is done so that I can proceed with
files resulting from the uncompress...
My prog needs to know that...
Hope I am a bit clearer...
Any help is appreciated
Try this:
Code:Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400
'JobtoDo - Program to run
'frm - Form
'You can do anything after the loop..shell another program if that program is close, load another version of your app, etc.
Sub Shell32Bit(ByVal JobToDo As String, frm As Form)
Dim hProcess As Long
Dim RetVal As Long
'The next line launches JobToDo as icon,
'captures process ID
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, 1))
Do
'Get the status of the process
GetExitCodeProcess hProcess, RetVal
'Sleep command recommended as well as DoEvents
DoEvents: Sleep 100
'Loop while the process is active
Loop While RetVal = STILL_ACTIVE
'Put your code here
'Events here occur when app is unloaded
End Sub
Usage:
Private Sub Command1_Click()
Call Shell32Bit("C:\App\App.exe", Me)
End Sub
Wow!
Matthew.... That's quite a piece..!
It looks very promising... I will try first, God willing,
first thing tomorrow morning
Thanks a lot...