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根据进程名强制关闭进程

Delphi 开关显示器操作

Delphi写的简单的文件的打开和关闭

Delphi 跳出for循环

Delphi webbrowser1 保存文档为 .html

Delphi 颜色表

关于Delphi xe5 firemonkey 手机屏幕自适应程序问题

Delphi调用rest

Delphi httpclient async异步获取网页代码

Delphi windows 编程[15] - 菜单消息: wm_command

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



打赏

取消

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

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

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

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

评论

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