CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    How do I make VB wait for a Shell command to be completed?

    I have a vb program that issues a shell command to execute an MS-DOS program. The MS-DOS program may take several minutes to completely process the data. I want vb to wait until this program has completed execution before executing the next line of code. Is this possible?


  2. #2
    Join Date
    Sep 1999
    Location
    Germany
    Posts
    66

    Re: How do I make VB wait for a Shell command to be completed?


  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: How do I make VB wait for a Shell command to be completed?

    This questions been asked several times on this forum - use the search button for 'shell' and 'wait' and you'll find several solutions.

    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  4. #4
    Join Date
    Nov 1999
    Location
    Los Angeles, CA
    Posts
    5

    Re: How do I make VB wait for a Shell command to be completed?

    Try using this code I wrote from API calls

    //{Module}
    Option Explicit

    Dim DemoDirectory$
    Public Const SYNCHRONIZE = &H100000
    Public Const INFINITE = &HFFFFFFFF ' Infinite timeout

    Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

    //{CLASS MODULE}
    Option Explicit

    Public Sub ShellnWait32(ByVal sEXEname As String)
    'Written by: Freddie Hurtado
    'Program Name: ShellnWait-32
    'Version: 1.0
    'Date: 09/02/99
    'Description: This program is an ActiveX Dll which accepts one parameter,
    ' EXEname as a string. It runs the EXE file and exits the
    ' program gracefully. It waits until the program completes
    ' execution before it releases itself so it runs well in a loop

    Dim pid&
    pid = Shell(sEXEname, vbNormalFocus)
    If pid <> 0 Then
    WaitForTerm1 pid
    End If

    End Sub

    Private Sub WaitForTerm1(pid&)
    ' This wait routine freezes the application
    ' It's clearly not a good way to wait for process
    ' termination - though if you hid the application
    ' first it could be very effective.
    Dim phnd&
    phnd = OpenProcess(SYNCHRONIZE, 0, pid)
    If phnd <> 0 Then
    Call WaitForSingleObject(phnd, INFINITE)
    Call CloseHandle(phnd)
    End If
    End Sub

    Compile this code as an activeX DLL. Dont forget to register it and reference it in your application.



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

Featured