Attribute VB_Name = "Shellfunc" Private Declare Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long Private Declare Function GetExitCodeProcess Lib "kernel32" _ (ByVal hProcess As Long, lpExitCode As Long) As Long Private Const STATUS_PENDING = &H103& Private Const PROCESS_QUERY_INFORMATION = &H400 Public Function Shellandwait(ExeFullPath As String, Optional TimeOutValue As Long = 0) As Boolean Dim lInst As Long Dim lStart As Long Dim lTimeToQuit As Long Dim sExeName As String Dim lProcessId As Long Dim lExitCode As Long Dim bPastMidnight As Boolean 'On Error GoTo ErrorHandler lStart = CLng(Timer) sExeName = ExeFullPath Debug.Print ExeFullPath 'Deal with timeout being reset at Midnight If TimeOutValue > 0 Then If lStart + TimeOutValue < 86400 Then lTimeToQuit = lStart + TimeOutValue Else lTimeToQuit = (lStart - 86400) + TimeOutValue bPastMidnight = True End If End If lInst = Shell(sExeName, vbMinimizedNoFocus) lProcessId = OpenProcess(PROCESS_QUERY_INFORMATION, False, lInst) Do Call GetExitCodeProcess(lProcessId, lExitCode) DoEvents If TimeOutValue And Timer > lTimeToQuit Then If bPastMidnight Then If Timer < lStart Then Exit Do Else Exit Do End If End If Loop While lExitCode = STATUS_PENDING Shellandwait = True Exit Function ErrorHandler: Shellandwait = False End Function Public Sub WriteMsg(msg) If Len(Form1.Text1.Text) > 8192 Then Form1.Text1.Text = Right$(Form1.Text1.Text, 4096) End If Form1.Text1.SelStart = Len(Form1.Text1.Text) Form1.Text1.SelText = msg & vbCrLf DoEvents End Sub