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
| procedure ShellAndWait(AppFullPath: PChar; Param: PChar);
var
StartInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
Fin: Boolean;
begin
// SOURCE WWW.DEVELOPPEZ.COM => F.A.Q. Delphi
// http://delphi.developpez.com/faq/?page=interexecution#lancercontroleapplication
{ 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, AppFullPath, Param, 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 }
Fin := False;
repeat
{ On attend la fin de l'application }
case WaitForSingleObject(ProcessInfo.hProcess, 200) of
WAIT_OBJECT_0: Fin := True; { L'application est terminée, on sort }
WAIT_TIMEOUT: ; { 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 Fin;
{ C'est fini }
end
else RaiseLastOSError;
end; |
Partager