Une commande
bonjour,
j'ai deux commandes Shell qui doivent s'excuter l'une apres l'autre
j'aimerais bien savoir est ce qu'il ya une maniere d'empecher l'execution de la deuxieme commande shell jusqu'a ce que la première se termine
bonne journée
alia
Voilà une possibilité :
Lance la calculatrice, attend que l'on quitte puis lance le bloque-notes.
Essaye ce code dans un nouveau projet exe avec une form qui contient un CommandButton nommé Command1
Option Explicit
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 Const PROCESS_ALL_ACCESS = &HF0000 Or &H100000 Or &HFFF
Private Const STILL_ACTIVE = &H103
Private Sub Command1_Click()
Dim lExec As Long
Command1.Enabled = False
lExec = Shell("calc.exe", vbNormalFocus)
WaitOnProgram lExec
lExec = Shell("notepad.exe", vbNormalFocus)
WaitOnProgram lExec
Command1.Enabled = True
End Sub
Private Function WaitOnProgram(ByVal idProg As Long) As Long
Dim iExit As Long, hProg As Long
hProg = OpenProcess(PROCESS_ALL_ACCESS, False, idProg)
GetExitCodeProcess hProg, iExit
Do While iExit = STILL_ACTIVE
DoEvents
GetExitCodeProcess hProg, iExit
Loop
CloseHandle hProg
WaitOnProgram = iExit
End Function