Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run an external program via vb and wait for it to finish 1

Status
Not open for further replies.

nhidalgo

MIS
Joined
Jun 13, 2001
Messages
619
Location
US
Is there a command or process to run a external command via vb and then pause execution of the vb program until the external program terminates. I have used "shell" before but dont' now how to pause.

Nick
 
I do not take credit for this code. It was found somewhere on this site.

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
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 Const SYNCHRONIZE = &H100000
Private Const INFINITE = -1&

Dim sPrgm As String
Dim lProcID As Long
Dim hProc As Long

Public Sub RunUntilFinished(ByVal sApp As String)

' Start the App
On Error GoTo ErrHndlr
lProcID = Shell(**NAME OF PROCCESS TO SHELL**, vbHide)
On Error GoTo 0

DoEvents

' Wait for the App
hProc = OpenProcess(SYNCHRONIZE, 0, lProcID)
If hProc <> 0 Then
WaitForSingleObject hProc, INFINITE
CloseHandle hProc
End If
Exit Sub

ErrHndlr:
MsgBox &quot;Error starting App:&quot; & vbCrLf & _
&quot;App: &quot; & sApp & vbCrLf & _
&quot;Err Desc: &quot; & Err.Description
Err.Clear
End Sub Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top