delphi判断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;
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 截取字符串的用法

Delphi 10.3.1 android沉浸式透明状态栏

Delphi自动提交网页表单和获取框架网页源码

Delphi scrollbox1滚动框鼠标滚轮

Delphi 把修改好的cookies重新赋值给webbrowser1 doc

Delphi xe 应用程序横竖屏设置

Delphi xe6 switch元件简繁问题

Delphi 谷歌api文本转换语音mp3文件

Delphi 提取字符串左侧内容

Delphi应用程序 paramstr()带有参数

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



打赏

取消

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

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

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

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

评论

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