DelphiFAQ Home Search:

Checking for a LAN connection

 

comments1 comments. Current rating: 4 stars (1 votes). Leave comments and/ or rate it.

To check for a LAN connection, various things can be done, like
checking for your username, or retrieving logon information from the
registry, but they can all fail if you consider a dockable notebook.
The following function searches for actual existing connections.

const
  MAX_NEIGHBORS = 20;

function NetAvailable : boolean;
var
  NetRes     : array [0..MAX_NEIGHBORS] of TNetResource;
  NNError,
  hEnum,
  EntryCount,
  NetResLen  : DWORD;
  loop1 : Integer;
begin
  hEnum := -1;
  Result := FALSE;
  try
    NNError := WNetOpenEnum (RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, Nil, hEnum);
    if NNError = NO_ERROR then
    begin
      while NNError <> ERROR_NO_MORE_ITEMS do
      begin
        EntryCount := 1;
        NetResLen := SizeOf (NetRes);
        NNError := WNetEnumResource (hEnum, EntryCount, @NetRes, NetResLen);
        if (NNError = NO_ERROR) then
        begin
          for loop1 := 1 to EntryCount do
          begin
            if Pos ('Microsoft', NetRes[0].lpProvider) = 1 then
            begin
              Result := TRUE;
              break
            end
          end
        end
        else
        begin
          break
        end
      end;
      WNetCloseEnum (hEnum); // close enum
    end
  except
    on exception do
      if DEBUG then
      begin
        ShowMessage ('Network Neighborhood Detection Failed.')
      end;
  end
end;

Content-type: text/html

Comments:

2006-02-19, 16:20:35
from Israel  
rating
unfortunelly this code doesnt work, it does enumurate the devices connected, but doesnt answer the question, as i like to say it, 'a cable was unplugged'
its answer will be 'theres still network!'

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: