'Voici un fonction qui permet de controler le retour d'une commande shell et donc d'attendre la fin de son exécution 'Les API à déclarer dans un module sont: Public Declare Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAccess As Long, _ ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long Public 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 Public Const PROCESS_QUERY_INFORMATION = &H400 Public Const STATUS_PENDING = &H103& 'La fonction est: Public Function RunShell(cmdline As String) as Long Dim hProcess As Long Dim ProcessId As Long Dim exitCode As Long On Error GoTo erreurRunShell ProcessId = Shell(cmdline) RunShell = ProcessId hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId) Do Call GetExitCodeProcess(hProcess, exitCode) DoEvents Loop While exitCode = STATUS_PENDING Call CloseHandle(hProcess) Exit Sub erreurRunShell: MsgBox Err.Description RunShell = 0 End Sub 'Ton code sera alors: compression = RunShell("c:\rar.exe a -r -m5 c:\tempo\archive.rar c:\vxdata\* ", 1) Set fs = CreateObject("Scripting.FileSystemObject") fs = fs.CopyFile("c:\tempo\*.rar", "d:")
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question