Obtain a list of the EXEs in execution  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 12/01/00

Tip accessed 473 times

 


  • Add 'TLHelp32' in the uses of your form
  • Put a TListBox (ListBox1) and a TButton (Button1) in your form
  • Put this code in the OnClick Button1:



     procedure TForm1.Button1Click(Sender: TObject);
    
         function SacaExe(MangoW:HWND):string;
         {Obtiene el EXE de una tarea}
         {get EXE of a task}
         var
           Datos    :TProcessEntry32;
           hID       : DWord;
           Snap    : Integer;
         begin
           GetWindowThreadProcessId(MangoW,@hID);
           Snap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
           try
             Datos.dwSize:=SizeOf(Datos);
             if(Process32First(Snap,Datos))then
             begin
               repeat
                 if Datos.th32ProcessID=hID then
                 begin
                   Result:=StrPas(Datos.szExeFile);
                   Break;
                 end;
               until not(Process32Next(Snap,Datos));
             end;
           finally
             Windows.CloseHandle(Snap);
           end;
         end;
    
    
        function ObtieneVentanas(Mango: HWND;
                 Nada: Pointer): Boolean; stdcall;
        var
           sTemp:string;
        begin
          Result := True;
          {Mango es el handle de la tarea encontrada}
          {Añadimos el .EXE si no está ya añadido...}
          sTemp:=SacaExe(Mango);
           with Form1.ListBox1.Items do
             if IndexOf(sTemp) = - 1 then Add(sTemp);
        end;
    
     begin
       EnumWindows( @ObtieneVentanas, 0 );
     end;