以下程序定时检测能否上网,如果不能上网,则重新启动电脑.在一般电脑上测试没出现问题,但是在服务器上就会占用越来越多的内存.
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw, ExtCtrls,WinInet, StdCtrls;type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Timer1: TTimer;
    Label1: TLabel;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
   
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
   Form1: TForm1;
   force   :Boolean;
  
implementation{$R *.dfm}
 function EnumWindowsCode(Wnd: hWnd; unUsed: Integer): Boolean; stdcall;
  var
    Buffer: Array[0..MAXBYTE-1] of Char;
 begin
    Result := True;
    GetClassName(Wnd, Buffer, MAXBYTE);
    if Buffer = 'IEFrame' then
    SendMessage(Wnd, WM_SYSCOMMAND , SC_CLOSE, 0);
  end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
  f: boolean;
  o: Variant;
  s: string;
  hToken       : THandle;
  tkp          : TTokenPrivileges;
  tkpo         : TTokenPrivileges;
  zero         : DWORD;
 begin  EnumWindows(@EnumWindowsCode,0);//关闭IE.
  WebBrowser1.Navigate('http://www.sohu.com');  f := false;
  if assigned(webbrowser1.Document) then
    begin
      o := webbrowser1.Document;
      s := o.location;
      if copy(s,1,4)='http' then f := true;
    end;
  if f then
    force:=true
  else
    force:=false;   //测试能否上网.  if Win32Platform=VER_PLATFORM_WIN32_NT then
     begin
        zero := 0;
        if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
           begin
             MessageBox( 0, 'PowerOff Error', 'OpenProcessToken() Failed', MB_OK );
             Exit;
           end;        if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid ) then
           begin
              MessageBox( 0, 'PowerOff Error', 'LookupPrivilegeValue() Failed', MB_OK );
              Exit;
           end;
        tkp.PrivilegeCount := 1;
        tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
        AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), tkpo, zero );
        if Boolean( GetLastError() ) then
           begin
              MessageBox( 0, 'PowerOff Error', 'AdjustTokenPrivileges() Failed', MB_OK );
              Exit;
           end
        else if Force then
            begin
               exit
              end
          else
             ExitWindowsEx( EWX_REBOOT, 0 );
      end
   else
        if Force then
          exit
         else
          ExitWindowsEx( EWX_REBOOT, 0 );
/////如果不能上网,就重新启动.  end;procedure TForm1.FormCreate(Sender: TObject);
begin
   WebBrowser1.Navigate('http://www.sohu.com');end;end.

解决方案 »

  1.   

    EnumWindows
    是呀!用到上面这个函数就会,
    我也急需要解决这个问题!!关注........
      

  2.   

    我也觉得内存的使用很大,我在任务列表中查看EXE使用的内存
    比如:使用ADO的EXE,在程序启动时有10MB,当我把EXE最小化时,看到的使用内存就变小了,为1MB多,还原窗体后,内存使用显示为4MB,这是什么现象?
      

  3.   

    从现象看是每次操作IE后没有有效释放资源而导致的,EnumWindows(@EnumWindowsCode,0);//关闭IE.你是不是有效的关闭了,如果在SERVER不适应的话就会导致内存递增。
      

  4.   

    占用内存不断增大,只是因为你用了WebBrowser你完全可以改用TidHttp这样的东西。
      

  5.   

    不知道如何使用楼上说的TidHttp
      

  6.   

    你用WebBrowser1来检查是否能上网.
    弓虽,不是一般的弓虽.