Entwickler-Ecke

Internet / Netzwerk - Prüfen,ob Verbindung zum Internet besteht?


majolo - Fr 07.03.03 16:16
Titel: Prüfen,ob Verbindung zum Internet besteht?
Hallo,

wie kann ich überprüfen, ob eine Verbindung zum Internet besteht?
Danke im vorraus.
Gruss
majolo


DaRkFiRe - Fr 07.03.03 16:41

Schau mal unter RASEnumConnections in der WinSDK-Hilfe nach. Brauchst dann nur noch die RAS HEADER...


derDoc - Fr 07.03.03 17:28

Falls du kein Platform SDK hast ist hier ein Auszug daraus:

Zitat:
RasEnumConnections

The RasEnumConnections function lists all active RAS connections. It returns each connection's handle and phone-book entry name.


DWORD RasEnumConnections(
LPRASCONN lprasconn,
LPDWORD lpcb,
LPDWORD lpcConnections
);

Parameters
lprasconn
[in, out] Pointer to a buffer that receives, on output, an array of RASCONN structures, one for each RAS connection.
On input, an application must set the dwSize member of the first RASCONN structure in the buffer to sizeof(RASCONN) in order to identify the version of the structure being passed.

lpcb
[in, out] Pointer to a variable that, on input, contains the size, in bytes, of the buffer specified by lprasconn.
On output, the function sets this variable to the number of bytes required to enumerate the RAS connections.

lpcConnections
[out] Pointer to a variable that receives the number of RASCONN structures written to the buffer specified by lprasconn.


bis11 - Fr 07.03.03 18:30

Hi,

ich hätte da zwei kleine Beispiele für Dich, die ich mal im Internet gefunden habe :

Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
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;


Beispiel 2:

Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
uses
  WinInet;

{...}

function IsConnectedToInternet: Boolean;
begin
  Result := (InternetGetConnectedState(nil, 0))
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if IsConnectedToInternet then
    ShowMessage('Connected.')
  else
    ShowMessage('Not Connected.')
end;


Wenn mich nicht alles täuscht hatte ich diese beiden Beispiel von dieser Seite [http://www.swissdelphicenter.ch] aus der Rubrik Programmiertipps


majolo - Fr 07.03.03 21:57

@bis11: Vielen Dank dein 2. Code hat wunderbar funktioniert.
Den anderen auch vielen Dank für ihre Mühe.

Gruss
majolo


Pyr0cracker - Mi 12.03.03 22:53

bei mir funzt er nicht.
liegt das daran das ich einxp habe?
wenn ja gibts noch eine andere möglichkeit das zu checken?
ciao,


Leathl - Mi 12.03.03 23:08

---