Delphi .NET (2) Database (75) Delphi IDE (239) Network (517) Printing (1037) Strings (2086) VCL (4255) Windows with Delphi (38)
Exchange Links About this site Links to us
|
Checking for a LAN connection
1 comments. Current rating: (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);
end
except
on exception do
if DEBUG then
begin
ShowMessage ('Network Neighborhood Detection Failed.')
end;
end
end; | |  | |  |
Content-type: text/html
Comments:
|
from Israel
|
 |
|
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!'
|
|