delphi双进程监控


本文整理自网络,侵删。

 program Pro2;

uses
Forms,Windows,TlHelp32,ShellAPI,Dialogs,SysUtils;
procedure delay(msecs:integer);
var
Tick: DWord;
Event: THandle;
begin
Event := CreateEvent(nil, False, False, nil);
try
Tick := GetTickCount + DWord(msecs);
while (msecs > 0) and (MsgWaitForMultipleObjects(1, Event, False, msecs, QS_ALLINPUT) <> WAIT_TIMEOUT) do
begin
Application.ProcessMessages;
msecs := Tick - GetTickcount;
end;
finally
CloseHandle(Event);
end;
end;

function HasPro(proName:String):Boolean;
var
flag:Boolean;
ProcessHandle:Thandle;
ProcessStruct:TProcessEntry32;
begin
Result:=False;
ProcessHandle:=createtoolhelp32snapshot(Th32cs_snapprocess,0);
processStruct.dwSize:=sizeof(ProcessStruct);
flag:=process32first(ProcessHandle,ProcessStruct);
while flag do
begin
if proName= StrPas(ProcessStruct.szExeFile) then Result:=True;
flag:=process32next(ProcessHandle,ProcessStruct);
end;
CloseHandle(ProcessHandle);
end;

begin
while True do
begin
if not HasPro('Pro1.exe') then
begin
WinExec('Pro1.exe',SW_HIDE);
end;
delay(10);
end;

end.

Pro1的代码和这个一样,最后的if not HasPro('Pro2.exe') then xxxxxxx,应该是没问题的,测试后用任务管理器关其中的一个进程,另外的进程会很快把它启起来,但不知道为什么,在关另外的进程就两个进程都关了。没时间去仔细研究。。

相关阅读 >>

Delphi hextoint

Delphi中禁止webbrowser右键的方法

Delphi 注入指定进程

推荐一套免费跨平台的Delphi 哈希及加密算法库

Delphi 提取网页源文件纯文本函数

Delphi 如何从html格式的字符串中提取纯文本?

Delphi2010获取鼠标指向窗口的位置及鼠标在窗口内的相对位置坐标

Delphi 数据库重置用户密码制作

Delphi 24位真彩色图形转化为ico文件

Delphi xe(indy10)tidbytes转ansistring的实现

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



打赏

取消

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

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

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

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

评论

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