目前在做一个小程序,想实现如下功能:当程序非正常退出时,如何可以让它自己重启呢?再做个监控程序的方案就算了吧,我在网上看到有个SetUnhandledExceptionFilter可以用,哪位老大说说这个咋用吧,谢谢!

解决方案 »

  1.   

    Enables an application to supersede the top-level exception handler of each thread of a process.After calling this function, if an exception occurs in a process that is not being debugged, and the exception makes it to the unhandled exception filter, that filter will call the exception filter function specified by the lpTopLevelExceptionFilter parameter.
    Syntax
    C++LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilter(
      __in  LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter
    );本人英文很菜,大概的意思是你调用了这个函数,那么程序出现异常的时候,都会被他捕捉到。
      

  2.   

    你可以把程序开发成服务程序,这个delphi开发win服务程序的网上很多
    服务程序可以设置在程序异常退出情况下重启
    win重启情况下自动启动等
      

  3.   

    try
    Code
    ...
    ...
    Except
     运行代码?、
     然后退出?、
    end;
    我想到的就这样了!
      

  4.   

    拦截Application的异常,在异常处理代码中,ShellExecute这个EXE就好了
      

  5.   

    用一个exe,导常退出你是不能完全拦到的,比如我用任务管理器结束了你的进程,你也能拦到?建议用两个exe,做进程守护。发现对方被杀立即重新启动对方,发现对方被删立即重新生成。可以用信号量,或互斥量,或用事件法(CreateEvent函数)等达到监测对方。
      

  6.   

    下面的可以重启,摆在....
    var
      StartInfo: TStartupInfo;
      ProcInfo: TProcessInformation;GetStartupInfo(StartInfo);
        FillChar(ProcInfo, SizeOf(TProcessInformation), #0);
        CreateProcess(nil, GetCommandLine, nil, nil, False,
          CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS, nil,
          '这里是程序路径', StartInfo, ProcInfo);  TerminateProcess(GetCurrentProcess, 1);  
      

  7.   

    守护进程(好像是UNIX系统的叫法),就是监控程序了
    做成Windows的服务程序也是一种办法,但这样程序功能实现要看一下是不是都适合做成服务程序。其实本质上还是守护进程,只不过是利用了系统自带的程序
      

  8.   

    获取心跳  建议用Socket 发包 
      

  9.   

    ……
    ……
    Self.Close;
    ShellExecute(Handle,'open',PChar(application.ExeName),nil,nil,SW_SHOW);
    ……
    ……