Merci pour ta réponse CariBensila. C'est bien cette procedure que l'on peut obtenir la liste des processus. Par contre, on n'a pas le nom de l'application executé (par exemple outlook.exe, on obtient Microsoft Outlook) mais c'est mieux que rien
Pour le gens que ca intérresse le code qui me liste tous mes processus est le suivant :
unit main;
{$mode delphi} interface
uses Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,Windows, Buttons, StdCtrls;
type
{ TFMain }
TFMain = class(TForm) B_Quitter: TBitBtn; B_Dictionnaire: TBitBtn; B_Parametre: TBitBtn; Memo1: TMemo; procedure B_ParametreClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { private declarations } public { public declarations } Liste_Processus : TStringList; end;
var FMain: TFMain;
implementation
{ TFMain }
// ce code vient de http://delphi.about.com/od/windowsshellapi/l/aa080304a.htm function EnumProcess(hHwnd: HWND; lParam : integer): boolean; stdcall; var pPid : DWORD; title, ClassName : string; texte : string; begin //if the returned value in null the //callback has failed, so set to false and exit. if (hHwnd=NULL) then //if (_para1=NULL) then begin result := false; end else begin //additional functions to get more //information about a process. //get the Process Identification number. GetWindowThreadProcessId(hHwnd,pPid); //set a memory area to receive //the process class name SetLength(ClassName, 255); //get the class name and reset the //memory area to the size of the name SetLength(ClassName,GetClassName(hHwnd,PChar(className),Length(className))); SetLength(title, 255); //get the process title; usually displayed //on the top bar in visible process SetLength(title, GetWindowText(hHwnd, PChar(title), Length(title))); //Display the process information //by adding it to a list box texte := 'Class Name = ' + className + '; Title = ' + title + '; HWND = ' +IntToStr(hHwnd) + '; Pid = ' + IntToStr(pPid); FMain.Liste_Processus.Add(texte);
Result := true; end; end;
procedure TFMain.FormCreate(Sender: TObject); var i:integer; begin FMain.Liste_Processus:=TStringList.Create;
end;
procedure TFMain.B_ParametreClick(Sender: TObject); var i : integer; begin FMain.Liste_Processus.Clear; if EnumWindows(@EnumProcess,0) = false then ShowMessage('Erreur: Impossible de récupérer les informations des processus.'); FMain.Memo1.Lines.Add('Nb processus actifs ='+inttostr(FMain.Liste_Processus.Count)); for i:=0 to FMain.Liste_Processus.Count-1 do begin FMain.Memo1.Lines.Add(FMain.Liste_Processus.Strings[i]) end; end;
procedure TFMain.FormDestroy(Sender: TObject); begin FMain.Liste_Processus.Free; // on libére le stringlist contenant les infos des processus end;
initialization {$I main.lrs}
end.
En tout cas merci Caribensila, ta réponse ma bien aiguillé.
Oniria
|