General information
Category:
Windows API functions
I have done something simloiar in one of my programs and have posted what I used. My chopped example below runs a DOS-based program and holds the VB execution until the program is finished running at which point it terminates the shelled app. I think all you are missing is the CloseHandle API but I put the rest of the code here just in case.
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFF
'Wait forever
Const WAIT_OBJECT_0 = 0
'The state of the specified object is signaled
Const WAIT_TIMEOUT = &H102
'The time-out interval elapsed & the object’s state
'is nonsignaled.
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub Form_Load
Dim lPid As Long
Dim lRet As Long
Dim lHnd As Long
lPid = Shell(CommandLine, vbHide)
If lPid <> 0 Then
'Get a handle to the shelled process.
lHnd = OpenProcess(SYNCHRONIZE, 0, lPid)
'If successful, wait for the application to end and close the handle.
If lHnd <> 0 Then
lRet = WaitForSingleObject(lHnd, INFINITE)
CloseHandle (lHnd)
End If
End If
End Sub
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only