DanielManchester
asked on
Internet connection
Using Delphi is there a way to determine if a client's machine has an internet connection?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ewangoya has given me a new approach. I think I might use a mix of the two. As an example, being connected to your local network would be proven by ewangoya's example. Being able to reach the end point would be proven by mine. Both could be useful.
Implement WININET.DLL and call function InternetGetConnectedState( ..)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
function InternetGetConnectedState(lpdwFlags: LPDWORD;dwReserved: DWORD): BOOL; stdcall; external 'WININET.DLL';
var
Form1: TForm1;
implementation
{$R *.dfm}
uses WinInet;
const
INET_CONN_MODEM = 1;
INET_CONN_LAN = 2;
INET_CONN_PROXY = 4;
INET_CONN_MODEM_BUSY = 8;
function IsConnectedToInternet: Boolean;
var
INetConnectionTypes: Integer;
begin
try
INetConnectionTypes := INET_CONN_MODEM + INET_CONN_LAN + INET_CONN_PROXY;
Result:= InternetGetConnectedState(@INetConnectionTypes, 0);
except
Result := false;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
If IsConnectedToInternet Then
ShowMessage('Connected to Internet!!!')
Else
ShowMessage('NOT connected to Internet!!!');
end;
end.
Open in new window
IsConnected('http://www.microsoft.com')