|
lazarus要如何写才能判断另一个进程是否存在?我想判断另一个程序是否运行了,如果运行了就退出该程序。
下面是我从网上找到用delphi写的win版判断代码,但linux、mac等系统下lazarus该怎么做?
###############################################
delphi判断进程是否存在
2009-05-29 02:36
unit Unit1;
interface
uses
Windows,TLHelp32, 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
function FindProcess(AFileName:string):boolean;
var
hSnapshot:THandle;
lppe:TProcessEntry32;
Found:Boolean;
begin
Result:=False;
hSnapshot:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
lppe.dwSize:=SizeOf(TProcessEntry32);
Found:=Process32First(hSnapshot,lppe);
while Found do
begin
if((UpperCase(ExtractFileName(lppe.szExeFile))=UpperCase(AFileName)) or (UpperCase(lppe.szExeFile )=UpperCase(AFileName))) then
begin
Result:=True;
end;
Found:=Process32Next(hSnapshot,lppe);
end;
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if FindProcess('QQ.exe')then
label1.Caption:='我看见你开QQ了哦'
else
label1.Caption:='小样连QQ都不开啊';
end;
end. |
|