Ciao Mesco,
potresti utilizzare questa funzione, che nell'esempio comanda WinZip. Naturalmente la devi adattare alle tue esigenze in conformità al programma che deve seguire.
codice:
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
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400
Private Sub Command1_Click()
Dim StringaComando As String
'Percorso di destinazione:
Dim ValoreDir As String
ValoreDir = "D:\Test\MioBk.zip"
' Percorso d'origine:
Dim FolOrig As String
FolOrig = "D:\Elaborazioni\Prova\DATI"
'Copia con WinZip:
Form1.MousePointer = 11
StringaComando = "C:\programmi\winzip\winzip32.exe -a -r " & ValoreDir & " " & FolOrig & ""
'Funzione per la copia ed il Backup:
Call RikShell(StringaComando)
Form1.MousePointer = 0
End Sub
Function RikShell(exe As String, Optional WinStyle) As Integer
Dim processid As Long
Dim hprocess As Long
Dim exitcode As Long
Dim parm As Integer
'Controllo il parametro opzionale finestra:
Select Case VarType(WinStyle)
Case vbEmpty, vbNull, vbError
parm = vbNormalFocus
Case vbLong, vbInteger, vbSingle, vbDouble
parm = WinStyle
Case Else
parm = vbNormalFocus
End Select
'Preleva l'ID del processo lanciato:
processid = Shell(exe, parm)
'Crea un Handle per quel processo:
hprocess = OpenProcess(PROCESS_QUERY_INFORMATION, False, processid)
Do
'Controlla ripetutamente che termini il backup:
Call GetExitCodeProcess(hprocess, exitcode)
'Lascia libero il sistema di processare le altre applicazioni:
DoEvents
Loop While (exitcode = STILL_ACTIVE)
CloseHandle (hprocess)
End Function