5 replies
You use the Shell object to run the batch file with the bWaitOnReturn value set to True. The next line won't execute until the batch file exits.
This vbscript snippet will give you the idea.
set oshell = CreateObject("Wscript.Shell")
oShell.run "Batchfilepath",0,True
more lines
by a_schwarze
see @129796 in MS-Knowledgebase
http://support.microsoft.com/default.aspx?scid=kb;en-us;129796
by
Andreas
The following code will not only do what you ask, it will allow you to set a timeout should you wish it to wait only up to a certain amount of time (to avoid locking up your app should the batch file not return):
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
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 Const SW_SHOWNORMAL = 1
Private Const INFINITE = -1&
Private Const SYNCHRONIZE = &H100000
' Shell out and suspend operation until the shelled process is complete
' Parameters are the Command and timeout (in milliseconds). If timeout is
' zero, then wait is infinite
Function Exec(Cmd As String, Optional Hide As Boolean, Optional TimeOut As Long, Optional ReturnState As Integer, Optional NoWait As Boolean) As Long
Dim iTask As Long, ret As Long, pHandle As Long, WaitTime As Long
WaitTime = TimeOut
If TimeOut = 0 Then WaitTime = INFINITE
If Hide Then
iTask = Shell(Cmd, vbHide)
Else
iTask = Shell(Cmd, vbNormalFocus)
End If
If NoWait <> True Then
Exec = iTask
pHandle = OpenProcess(SYNCHRONIZE, False, iTask)
ReturnState = WaitForSingleObject(pHandle, WaitTime)
If ReturnState <> 0 Then Shell "kill " & Format$(iTask), vbHide
ret = CloseHandle(pHandle)
End If
End Function
by ammamukesh
Thanks a lot, friend.
by ammamukesh
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending