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 41 42 43
| procedure TForm1.Attente;
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);
{ cacher la fenetre}
With Startinfo do
begin
cb := SizeOf(TStartupInfo);
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := SW_HIDE;
end;
{ Lancement de la ligne de commande }
If CreateProcess(Nil, '"cmd" "/c net view > c:\network.txt"', 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 }
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 }
listage;
End
Else RaiseLastOSError;
end; |
Partager