delphi 如何判断一个EXE文件是否运行


本文整理自网络,侵删。

 如何判断一个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 调用js脚本

Delphi操作多显示器

Delphi 删除确认对话框

Delphi研究之驱动开发篇(六)--利用section与用户模式程

Delphi中怎么判断一个文件夹是否为空

Delphi 判断一目录是否共享

Delphi 屏幕取色

Delphi wmi 取硬件信息

Delphi - 右滚动文字

Delphi实现暴力瞬间关机

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...