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;
相关阅读 >>
Delphi执行sql提示“不正常地定义参数对象”,“提供了不一致或不完整的信息”错误
更多相关阅读请进入《Delphi》频道 >>