codice:
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Const STATUS_PENDING = &H103&
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Sub ShellAndWait(sFile As String, Visualizzazione As Long)
Dim hProcess As Long
Dim ProcessId As Long
Dim CodExit As Long
ProcessId = Shell(sFile, Visualizzazione)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
Do
Call GetExitCodeProcess(hProcess, CodExit)
DoEvents
Loop While CodExit = STATUS_PENDING
Call CloseHandle(hProcess)
End Sub
per usarla
codice:
call ShellAndWait("percorso tuo file", vbhide)
dopo di che puoi leggere tranquillamente il file perchè la funzione non esce finche il processo dell'eseguibile non è killato ti consiglio comunque di controllare che il file esista