deross
asked on
Shell command
I have a small program in VB5 that launches another program. I have included the following code to end the program once the other application has started:
RetVal = Shell("c:\otherprogram.exe ", 1)
window_name = "otherprogram"
Running = Format$(FindWindow(class_n ame, window_name))
Do
DoEvents
Loop While Running = 0
End
My problem is, the application I am trying to launch is quite large and takes a lot of time to load. My application finds the window name before the program has actually started causing it to end pre-maturely and showing any existing windows beneath. Is there a way to make sure my application does not end until the program it is launching is fully loaded?
Thanks
RetVal = Shell("c:\otherprogram.exe
window_name = "otherprogram"
Running = Format$(FindWindow(class_n
Do
DoEvents
Loop While Running = 0
End
My problem is, the application I am trying to launch is quite large and takes a lot of time to load. My application finds the window name before the program has actually started causing it to end pre-maturely and showing any existing windows beneath. Is there a way to make sure my application does not end until the program it is launching is fully loaded?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Include the following in the header of module.
Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Const STANDARD_RIGHTS_ALL = &H1F0000
Public Const INFINITE = &HFFFF
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Call the following function with the handle that is returned from the Shell command.
Function:
Public Function CommandExecuted(hAppHandle
Dim hProc As Long
Dim ReturnValue As Integer
' Wait for the shelled application to finish:
hProc = OpenProcess(STANDARD_RIGHT
If hProc <> 0 Then
ReturnValue = WaitForSingleObject(hProc,
CloseHandle hProc
End If
CommandExecuted = True
Exit Function
CommandExecuted_Err:
CommandExecuted = True
End Function