Shell and Wait
Shell and Wait
Permet d'exécuter une ligne de commande et d'attendre la fermeture de l'application avant de poursuivre.
'/ '/ A placer dans la partie déclarative '/ Declare Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAccess As Long, _ ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long Declare Function GetExitCodeProcess Lib "kernel32" _ (ByVal hProcess As Long, lpExitCode As Long) As Long Public Declare Function CloseHandle Lib "kernel32" _ (ByVal hObject As Long) As Long
La fonction :
Public Sub ExecCmd(strCmdline As String) ' Permet de lancer une tache et d'attendre que celle-ci ' soit terminée avant de poursuivre On Error GoTo Err_ExecCmd Const STILL_ACTIVE = &H103& Dim lngREt As Long Dim processID As Long Dim processHandle As Long Dim lExitCode As Long processID = Shell(strCmdline, vbNormalFocus) processHandle = OpenProcess(1048576, True, processID) Do DoEvents ' Determine si le Process est encore actif lngREt = GetExitCodeProcess(processHandle, lExitCode) If Not (lExitCode = STILL_ACTIVE) Then Exit Do Loop While True ' Fermer le Handle lorsque plus utilisé. CloseHandle (processHandle) CloseHandle (processHandle) Exit_ExecCmd: Exit Sub Err_ExecCmd: MsgBox "ExecCmd" & " " & Err.Number & Err.Description Resume Exit_ExecCmd End Sub
Dernière modification : 08/02/2010 01:53
Catégorie : Les mémos - Administration
Page lue 8825 fois