- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi通过进程名获取进程PID函数
uses TLhelp32;
Function GetPID(_GetPID:String):String;
var
h:thandle;
f:boolean;
lppe:tprocessentry32;
begin
h := CreateToolhelp32Snapshot(TH32cs_SnapProcess, 0);
lppe.dwSize := sizeof(lppe);
f := Process32First(h, lppe); //lppe.szExeFile是进程的名字,自己挑选你要的
//lppe.th32ProcessID就是你要的进程号
while integer(f) <> 0 do
begin
//if lppe.szExeFile=‘QQ.exe‘ then showmessage(‘ok‘);
if lppe.szExeFile = _GetPID then
begin
Result:=(inttostr(lppe.th32ProcessID));
break;
end;
f := Process32Next(h, lppe);
end;
end;