本文整理自网络,侵删。
如何判断一个EXE文件是否运行了呢?这里用到一个函数:
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;
用法:
如我们要判断'app.exe'程序是否正在运行/是否已经启动
if exe_is_running('app') then
....
else
....
相关阅读 >>
Delphi {$pointermath on} 方便指针操作的编译指令
Delphi 操作 pdf -- 使用 acrobat sdk 初探
Delphi fdconnection执行sql execsql
Delphi中如何判断mediaplayer控件所播放的文件是否播放完毕?
Delphi xe6开发的android应用实现在线升级完成后自动安装apk代码(加说明)
更多相关阅读请进入《Delphi》频道 >>