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;
|