1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
'API
Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName 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
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
'Constante d'execution
Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&
Public Const CREATE_NO_WINDOW = &H8000000
'Type sur les informations du process
Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
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 Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
'Permet de lancer un process et d'attendre qu'il se termine avant de poursuivre le programme
'CommandeAExecuter : Instruction à traiter
'Fenetre : Indique si la fenêtre est visible ou non
Public Sub ExecuteTraitement(CommandeAExecuter As String, Fenetre As Boolean)
Dim refProcessInformation As PROCESS_INFORMATION
Dim refProcessStart As STARTUPINFO
Dim valRetour As Long
'Lance l'application
refProcessStart.cb = Len(refProcessStart)
If Fenetre Then
valRetour = CreateProcessA(0&, CommandeAExecuter, 0&, 0&, 1&, CREATE_NO_WINDOW, 0&, 0&, refProcessStart, refProcessInformation)
Else
valRetour = CreateProcessA(0&, CommandeAExecuter, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, refProcessStart, refProcessInformation)
End If
'Attente que l'application soit terminée
valRetour = WaitForSingleObject(refProcessInformation.hProcess, INFINITE)
valRetour = CloseHandle(refProcessInformation.hProcess)
End Sub |