Click to See Complete Forum and Search --> : How do I make VB wait for a Shell command to be completed?
October 22nd, 1999, 10:17 AM
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?
smalig
October 22nd, 1999, 11:03 AM
Look at
http://www.vb-world.net/tips/tip5.html
Best regards.
smalig@hotmail.com
http://smalig.tripod.com
Chris Eastwood
October 22nd, 1999, 04:11 PM
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
Freddie
November 29th, 1999, 06:22 PM
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.