当前位置:编程学习 > Delphi >>

delphi 检测某进程存在后执行弹出messagebox?

delphi 检测DNF.EXE进程存在后执行弹出messagebox说!“已经运行!”

怎么写这个代码?谢谢

追问:

直接复制进去就能用吗?我复制进去没用啊

答案:EnumProcess + GetModuleBaseName实现,代码如下:

uses windows, psapi;

var
aps:array[1..1024] of DWORD;
hProcess, cb:cardinal;
procCnt, hModule:DWORD;
i:integer;
ret:LongBool;
moduleFileName:array[1..100] of ansichar;

begin
EnumProcesses( @aps, sizeof( aps ), cb );
procCnt := cb div sizeof( DWORD );
for i:=1 to procCnt do
begin
hProcess := OpenProcess( PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, false, aps[i] );
if hProcess = 0 then continue;
ret := EnumProcessModules( hProcess, @hModule, sizeof(hModule), cb );
if not ret then continue;
GetModuleBaseName( hProcess, hModule, @moduleFileName, sizeof( moduleFileName ) );
if lstrcmpi( @moduleFileName, 'qq.exe' ) = 0 then
MessageBox( 0, '已经运行', 'xxx', MB_OK );
end;
end.

望采纳

上一个:c visual c++ vb delphi 各是什么意思
下一个:Delphi的最高层次是什么?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,