Versuchs einfach mal so:
Delphi-Quellcode:
uses
StdCtrls, registry;
function IsConnected: Boolean;
var
reg: TRegistry;
buff: DWORD;
begin
reg := TRegistry.Create;
Reg.RootKey := HKey_local_machine;
if reg.OpenKey('\System\CurrentControlSet\Services\RemoteAccess', False) then
begin
reg.ReadBinaryData('Remote Connection', buff, SizeOf(buff));
Result := buff = 1;
reg.CloseKey;
reg.Free;
end;
end;
Ist zwar mit registry funktioniert aber gut...
Zweite Möglichkeit:
Delphi-Quellcode:
uses
WinInet;
{...}
function IsConnectedToInternet: Boolean;
var
dwConnectionTypes: DWORD;
begin
dwConnectionTypes :=
INTERNET_CONNECTION_MODEM +
INTERNET_CONNECTION_LAN +
INTERNET_CONNECTION_PROXY;
Result := InternetGetConnectedState(@dwConnectionTypes, 0);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if IsConnectedToInternet then
ShowMessage('Connected.')
else
ShowMessage('Not Connected.')
end;
Dritte Möglichkeit:
Delphi-Quellcode:
function IsConnectedToInternet(lpdwFlags: LPDWORD): Boolean;
const
WininetDLL = '
wininet.dll';
var
hWininetDLL: THandle;
dwReserved: DWORD;
fn_InternetGetConnectedState:
function(lpdwFlags: LPDWORD; dwReserved: DWORD): BOOL;
stdcall;
begin
Result := False;
dwReserved := 0;
hWininetDLL := LoadLibrary(WininetDLL);
if hWininetDLL > 0
then
begin
@fn_InternetGetConnectedState := GetProcAddress(hWininetDLL,'
InternetGetConnectedState');
if Assigned(fn_InternetGetConnectedState)
then
begin
Result := fn_InternetGetConnectedState(lpdwFlags, dwReserved);
end;
FreeLibrary(hWininetDLL);
end else
raise Exception.Create('
Unable to locate function InternetGetConnectedState in library ' + WininetDLL);
end;

irgendwas sollte ja von denen deinen erwartungen entsprechen...