Appli terminée???

cs_Troopers Messages postés 81 Date d'inscription lundi 18 février 2002 Statut Membre Dernière intervention 29 août 2003 - 28 févr. 2002 à 10:29
cs_Troopers Messages postés 81 Date d'inscription lundi 18 février 2002 Statut Membre Dernière intervention 29 août 2003 - 28 févr. 2002 à 14:20
Bonjour!

Comment faire pour savoir si une appli est terminée?

En fait je lance un .bat avec
Shell App.Path & "\X.BAT", vbNormalFocus
et je veux savoir quand son execution est terminée

2 réponses

cs_LUDEr Messages postés 27 Date d'inscription mardi 12 février 2002 Statut Membre Dernière intervention 21 juin 2002
28 févr. 2002 à 13:38
Salut,

il ne faut pas utiliser la commande shell, mais l'instruction RunProcess du module suivant:

Option Explicit

Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&

Public 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 Long
cbReserved2 As Long
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadID As Long
End Type

'Note: the number of line continuations in
'the next declare may exceed VB's maximum; the API is
'presented this way here only for clarity.
Public Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpAppName As Long, _
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 lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long

Public Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Public Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Public Sub RunProcess(cmdline As String)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim r As Long
Call CreateProcessA(0&, cmdline, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
'Wait for the application to finish
Call WaitForSingleObject(proc.hProcess, INFINITE)
'Close the handle to the process
Call CloseHandle(proc.hProcess)
'Close the handle to the thread created
Call CloseHandle(proc.hThread)
End Sub
0
cs_Troopers Messages postés 81 Date d'inscription lundi 18 février 2002 Statut Membre Dernière intervention 29 août 2003
28 févr. 2002 à 14:20
THANKS
0
Rejoignez-nous