如何获得进程名

来源:百度知道 编辑:UC知道 时间:2024/09/21 11:00:12
已经知道 进程ID 如何 获得进程名呢 ?工具 delphi

//uses TLhelp32
function GetProcessNameById(const AID: Integer): String;
var
h:thandle;
f:boolean;
lppe:tprocessentry32;
begin
Result := '';
h := CreateToolhelp32Snapshot(TH32cs_SnapProcess, 0);
lppe.dwSize := sizeof(lppe);
f := Process32First(h, lppe);
while integer(f) <> 0 do
begin
if Integer(lppe.th32ProcessID) = AID then
begin
Result:= StrPas(lppe.szExeFile);
break;
end;
f := Process32Next(h, lppe);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(GetProcessNameById(1736));
end;