General information
Category:
Coding, syntax & commands
The following code shells out to the application and retrieves the new windows handle value (the unique identifier to windows). It then puts itself into a holding pattern until the shelled window is terminated. So keep in mind that your VB execution is halted until the shelled window is closed. Cheers.
'the next 7 lines should be in the General Declarations section
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFF
Const WAIT_OBJECT_0 = 0
Const WAIT_TIMEOUT = &H102
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
'Include the following block of code wherever you want
Dim lPid As Long
Dim lRet As Long
Dim lHnd As Long
lPid = Shell("c:\windows\notepad.exe", 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
Previous
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