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 38 39 40
|
Options est un record et emplacement un de ses éléments de type string
procedure TMainForm.LaunchClick(Sender: TObject);
Var StartInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
Fin : Boolean;
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(Options.Emplacement) , Nil, Nil, False,
0, Nil, Nil, StartInfo,ProcessInfo) Then
Begin
lblaunched.Caption := 'oui';
{ 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. }
If Hidded then ShowWindow(Processinfo.hThread, SW_HIDE)
else ShowWindow(Processinfo.hThread, SW_SHOW);
Application.ProcessMessages;
Until Fin;
lblaunched.Caption := 'non';
End
Else RaiseLastOSError;
end; |
Partager