频道分类

Delphi获取进程PID

作者:admin 来源:未知 日期:2010/1/30 16:52:48 人气: 标签:

 Delphi获取进程PID

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
hwin:dword;
pid:dword;
begin
hwin:=FindWindow(nil,'新建 文本文档.txt - 记事本');
getwindowthreadprocessid(hwin,pid);
if pid=0 then
label1.caption:='wrong'
else
label1.Caption :=inttostr(pid);
end;
end.