Results 1 to 2 of 2

Thread: [help] shell and wait for child programs??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    117

    [help] shell and wait for child programs??

    ok, I need to open an external program and wait for it to finish running before my code continues...

    i would normally just "shell and wait" except for a slight glitch...

    the external program opens a secondary program and then closes itself (after some necessary actions are performed)... I need my "shell and wait" to wait for both the external program and the secondary program it launches to close before continuing...

    if possible, it'd be nice to only hard code the filepaths of the two programs, and generate any other necessary properties at runtime.


    any ideas??

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: [help] shell and wait for child programs??

    VB Code:
    1. ' Start the indicated program and wait for it
    2. ' to finish, hiding while we wait.
    3. Private Sub ShellAndWait(ByVal program_name As String)
    4. Dim process_id As Long
    5. Dim process_handle As Long
    6.  
    7.     ' Start the program.
    8.     On Error GoTo ShellError
    9.     process_id = Shell(program_name, vbNormalFocus)
    10.     On Error GoTo 0
    11.  
    12.     ' Hide.
    13.     Me.Visible = False
    14.     DoEvents
    15.  
    16.     ' Wait for the program to finish.
    17.     ' Get the process handle.
    18.     process_handle = OpenProcess(SYNCHRONIZE, 0, process_id)
    19.     If process_handle <> 0 Then
    20.         WaitForSingleObject process_handle, INFINITE
    21.         CloseHandle process_handle
    22.     End If
    23.  
    24.     ' Reappear.
    25.     Me.Visible = True
    26.     Me.SetFocus
    27.     Exit Sub
    28.  
    29. ShellError:
    30.     MsgBox "Error starting task " & txtProgram.Text & vbCrLf & Err.Description
    31. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width