INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Visual Basic (Microsoft) Versions 5/6 FAQ

Windows API

Run Shelled App and Wait Until Finished by dsi
Posted: 26 Jan 01


Option Explicit

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&
'-----------------------------------------------------------
Sub Main()
    Dim sPrgm As String
    
    sPrgm = "C:\Winnt\notepad.exe"
    
    RunUntilFinished sPrgm
    
    MsgBox "App is finished!"

    End
End Sub
'-----------------------------------------------------------
Public Sub RunUntilFinished(ByVal sApp As String)
    Dim lProcID As Long
    Dim hProc As Long

    ' Start the App
    On Error GoTo ErrHndlr
    lProcID = Shell(sApp, vbNormalFocus)
    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 "Error starting App:" & vbCrLf & _
           "App: " & sApp & vbCrLf & _
           "Err Desc: " & Err.Description
    Err.Clear
End Sub


Back to Visual Basic (Microsoft) Versions 5/6 FAQ Index
Back to Visual Basic (Microsoft) Versions 5/6 Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close