delphi 双进程监控保护  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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,应该是没问题的,测试后用任务管理器关其中的一个进程,另外的进程会很快把它启起来,但不知道为什么,在关另外的进程就两个进程都关了。没时间去仔细研究。。

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.041558027267456 seconds