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
| // Fonction Execution d'un programme + gère l'état
// Renvoie True si le programme est terminé
function ExecuteProgramme(CommandProcess :String) :Boolean;
Var StartInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
begin
{ Mise à zéro de la structure StartInfo }
FillChar(StartInfo,SizeOf(StartInfo),#0);
{ Seule la taille est renseignée, toutes les autres options }
{ laissées à zéro prendront les valeurs par défaut }
StartInfo.cb := SizeOf(StartInfo);
{ Lancement de la ligne de commande }
If CreateProcess(Nil, PChar(CommandProcess), Nil, Nil, False,
0, Nil, Nil, StartInfo,ProcessInfo) Then
Begin
{ L'application est bien lancée, on va en attendre la fin }
{ ProcessInfo.hProcess contient le handle du process principal de l'application }
result:=False;
Repeat
{ On attend la fin de l'application }
Case WaitForSingleObject(ProcessInfo.hProcess, 200)Of
WAIT_OBJECT_0 :result:=True; { L'application est terminée, on sort }
WAIT_TIMEOUT :result:=False; { elle n'est pas terminée, on continue d'attendre }
End;
{ Mise à jour de la fenêtre pour que l'application ne paraisse pas bloquée. }
Application.ProcessMessages;
Until Result;
{ C'est fini }
result := True;
End
Else
begin
result := True;
RaiseLastOSError;
end;
end; |
Partager