woshihaoge 感谢! 按你的方法,我实现了,不知道碰到程序假死,会不会生效。还没有测试到。 代码: public { Public declarations } SI : TStartupInfo; PI : TProcessInformation; form.show 加入: FillChar(SI,sizeof(SI),#0); with SI do begin cb:=sizeof(SI); dwFlags:=StartF_UsesTDHandles or STARTF_USESHOWWINDOW; lptitle:=nil;//pchar('gxtvodserver'); wShowWindow:=SW_Show; end; //Application.ProcessMessages; CreateProcess(PChar(exefile),nil,nil,nil,true,IDLE_PRIORITY_CLASS,nil,nil,SI,PI); //MyHandle:=OpenProcess(PROCESS_TERMINATE, true, pi.dwProcessId); //开始监控 Timer1.Enabled:=TRUE;procedure TForm1.Timer1Timer(Sender: TObject); var ExitCode:DWORD; begin //Handle:=OpenProcess(PROCESS_TERMINATE, true, PI.dwProcessId); GetExitCodeProcess(PI.hProcess, ExitCode); if not(ExitCode=STILL_ACTIVE) then //STILL_ACTIVE begin //showmessage('进程已经关闭'); Timer1.Enabled := FALSE ; if chksetting() then begin RestartSvr();//start service end; end;
woshihaoge 感谢! 是否有点复杂.
<b> 能不能说具体一点 </b>
woshihaoge 感谢! 按你的方法,我实现了,不知道碰到程序假死,会不会生效。还没有测试到。 代码: public
{ Public declarations }
SI : TStartupInfo;
PI : TProcessInformation; form.show 加入: FillChar(SI,sizeof(SI),#0);
with SI do
begin
cb:=sizeof(SI);
dwFlags:=StartF_UsesTDHandles or STARTF_USESHOWWINDOW;
lptitle:=nil;//pchar('gxtvodserver');
wShowWindow:=SW_Show;
end; //Application.ProcessMessages;
CreateProcess(PChar(exefile),nil,nil,nil,true,IDLE_PRIORITY_CLASS,nil,nil,SI,PI);
//MyHandle:=OpenProcess(PROCESS_TERMINATE, true, pi.dwProcessId); //开始监控
Timer1.Enabled:=TRUE;procedure TForm1.Timer1Timer(Sender: TObject);
var
ExitCode:DWORD;
begin //Handle:=OpenProcess(PROCESS_TERMINATE, true, PI.dwProcessId);
GetExitCodeProcess(PI.hProcess, ExitCode);
if not(ExitCode=STILL_ACTIVE) then //STILL_ACTIVE
begin
//showmessage('进程已经关闭');
Timer1.Enabled := FALSE ;
if chksetting() then
begin
RestartSvr();//start service
end;
end;
FindWindow 不准确,回勿杀进程!