您现在的位置:首页 >> 硬件系统 >> 硬件系统 >> 内容

Delphi通过进程名获取进程PID函数

时间:2011/9/3 15:21:21 点击:

  核心提示:usesTLhelp32;Function GetPID(_GetPID:String):String;var h:thandle; f:boolean; lppe:tprocessentry32;b...

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;

作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号