Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Start new application and wait for it to finish


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 Const SYNCHRONIZE = &H100000
Private Const INFINITE = - 1&

'start the indicated program and wait for it to finish
Private Sub ShellAndWait( ByVal program_Name As String )
Dim process_id As Long
Dim process_handle As Long

process_id = Shell(program_Name, vbNormalFocus)
process_handle = OpenProcess(SYNCHRONIZE, 0, process_id)
If process_handle <> 0 Then
   WaitForSingleObject process_handle, INFINITE
   CloseHandle process_handle
End If
End Sub