Delphi 根据进程名称获取进程号:
Function GetPID(_GetPID: String;): integer;
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 Pos(_GetPID, lppe.szExeFile) > 0 then
begin
Result := lppe.th32ProcessID;
end;
f := Process32Next(h, lppe);
end;
end;
欢迎分享,(木庄网络博客交流QQ群:562366239)