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
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question