Para eso tendrías que crear el proceso usando CreateProcess y luego llamar a WaitForSingleObject hasta que termine dicho proceso.
Escribí un ejemplo para que te quede más claro. El siguiente procedimiento ExecuteAndWait no volverá hasta que termine la descarga o hasta que la variable global CancelDownload se establezca a True.
Saludos.
Escribí un ejemplo para que te quede más claro. El siguiente procedimiento ExecuteAndWait no volverá hasta que termine la descarga o hasta que la variable global CancelDownload se establezca a True.
Código [Seleccionar]
Option Explicit
Const STARTF_USESHOWWINDOW = &H1
Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public CancelDownload As Boolean
Sub ExecuteAndWait(CommandLine As String, Optional ShowWindow As VbAppWinStyle)
Dim lpProcess As PROCESS_INFORMATION
Dim lpStartup As STARTUPINFO
Dim r&
' Oculta la ventana del proceso.
'
lpStartup.dwFlags = STARTF_USESHOWWINDOW
lpStartup.wShowWindow = ShowWindow
' Se debe establecer el valor inicial del
' tamaño de la estructura.
'
lpStartup.cb = LenB(lpStartup)
' Crea el proceso.
'
r = CreateProcess(vbNullString, CommandLine, 0&, 0&, False, 0&, 0&, _
vbNullString, lpStartup, lpProcess)
If r Then
' Si el proceso se creo correctamente.
'
Do While WaitForSingleObject(lpProcess.hProcess, 100)
' Espera hasta que termine el proceso.
'
If CancelDownload Then
'Cancelar la espera.
'
Exit Sub
End If
DoEvents
Loop
CancelDownload = False
' Libera el controlador de proceso.
'
Call CloseHandle(lpProcess.hProcess)
End If
End Sub
Saludos.