本文整理自网络,侵删。
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 twebbrowser get html source after ajax load
Delphi xe5开发android程序调用电话相关功能(短信息和电话)
更多相关阅读请进入《Delphi》频道 >>