All pastes #287730 Raw Edit

Anonymous

public text v1 · immutable
#287730 ·published 2006-12-21 18:49 UTC
rendered paste body
Function ShellAndWait(sCommandLine As String, Optional lState As Long = vbNormalFocus) As Long
    Dim lRetVal As Long

    If FileExists(sCommandLine) Then
        If Left$(sCommandLine, 1) <> Chr$(34) Then
            sCommandLine = Chr$(34) & sCommandLine
        End If
        If Right$(sCommandLine, 1) <> Chr$(34) Then
            sCommandLine = sCommandLine & Chr$(34)
        End If
    End If
    
    lRetVal = Shell(sCommandLine, lState)
    ShellAndWait = OpenProcess(SYNCHRONIZE, True, lRetVal)
    
    Do
        lRetVal = WaitForSingleObject(ShellAndWait, 0)
        If lRetVal = WAIT_OBJECT_0 Then
            lRetVal = CloseHandle(ShellAndWait)
            Exit Do
        ElseIf lRetVal = WAIT_FAILED Then
            lRetVal = CloseHandle(ShellAndWait)
            Exit Do
        End If
        Pause 100
        'Pause 500
    Loop
End Function