function exe_is_running(const exeName:String) : Boolean; //exeName:不要扩展名的Exe主文件名
var
hCurrentWindow:HWnd;
szText:array[0..254] of char;
begin
Result := False;
hCurrentWindow:=Getwindow(Application.Handle,GW_HWNDFIRST);
while hCurrentWindow <> 0 do
begin
if Getwindowtext(hCurrentWindow,@sztext,255)>0 then
begin
if LowerCase(pchar(@sztext))=LowerCase(exeName) then
begin
Result := true;
Exit;
end;
end;
hCurrentWindow:=Getwindow(hCurrentwindow,GW_HWndNext);
end;
end;
var
hCurrentWindow:HWnd;
szText:array[0..254] of char;
begin
Result := False;
hCurrentWindow:=Getwindow(Application.Handle,GW_HWNDFIRST);
while hCurrentWindow <> 0 do
begin
if Getwindowtext(hCurrentWindow,@sztext,255)>0 then
begin
if LowerCase(pchar(@sztext))=LowerCase(exeName) then
begin
Result := true;
Exit;
end;
end;
hCurrentWindow:=Getwindow(hCurrentwindow,GW_HWndNext);
end;
end;
用法:
如我们要判断'Live.exe'程序是否正在运行/是否已经启动
if exe_is_running(Live) then
....
else
....
本文转自 OldHawk 博客园博客,原文链接:http://www.cnblogs.com/taobataoma/archive/2007/08/15/856401.html,如需转载请自行联系原作者