本文整理自网络,侵删。
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;
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;
用法:
如我们要判断'ScktSrvr.exe'程序是否正在运行/是否已经启动
if exe_is_running('ScktSrvr') then
....
else
....
相关阅读 >>
Delphi generics collections tdictionary 用法
Delphi xp 之后, Delphi 动注册表不方便了...逼出来一个办法:
Delphi ioutils 单元(5): tdirectory.tdirectory 的其他功能
Delphi win32,win64用于单/多线程计数素数的整数性能比较
更多相关阅读请进入《Delphi》频道 >>