以下好像可以
function InetIsOffline(Flag: Integer): Boolean; stdcall; external 'URL.DLL';
调用代码:
procedure TFrmInternetDemo.Button1Click(Sender: TObject);
begin
if InetIsOffline(0) then
ShowMessage('This computer is not connected to Internet!')
else
ShowMessage('You are connected to Internet!');
end;
或者
uses WinInet;
function IsOnline:Boolean;
var
ConnectState,StateSize
WORD;
begin
Result:=False;
if not InternetCheckConnection('http://www.microsoft.com/',1,0) then
Exit;
ConnectState:=0;
StateSize:=SizeOf(ConnectState);
if InternetQueryOption(nil,INTERNET_OPTION_CONNECTED_STATE,@ConnectState,StateSize) then
if (ConnectState and INTERNET_STATE_DISCONNECTED)<>2 then
Result:=True;
end;