I need to detect whether or not I currently have a network connection. I am on a LAN not a dialup.
Any solutions...
Printable View
I need to detect whether or not I currently have a network connection. I am on a LAN not a dialup.
Any solutions...
When you are not directly connected to the internet you can't detect if you are. You could try to ping a site and when you get an answer you're connected but I don't see direct way.
Or you install a server-application on the server which sends you the current connectionstate via LAN to a client-app... ;)
Or do you just want to know if you have an active LAN-Connection?
For info on how to determine if your internet connection is via a LAN, take a look in the Previous Topic.
To detect if you are on a LAN with no internet connection, well ... I'll get back :D
Thanx for the input Stryker. Worked great.
If you come up with how to detect a LAN without an internet connection I'd be very interested
Just try and find another computer on the LAN (or a known server).
That's what we do for our VB/ASP app... I try and map to the server, and if it's not available -- it'll tell me...
I'll see if I can find the code and post tomorrow. It's part of the WNetOpenEnum API - one of the errors will return is ERROR_NO_NETWORK.
I don't have the VB code handy but :
Code:DWORD WNetOpenEnum(
DWORD dwScope, // scope of enumeration
DWORD dwType, // resource types to list
DWORD dwUsage, // resource usage to list
LPNETRESOURCE lpNetResource,
// pointer to resource structure
LPHANDLE lphEnum // pointer to enumeration handle buffer
);
Ah ha! I found it :P
This will tell you if the network if available or not.Code:Public Sub ListDomainComputers(p_strDomain As String, p_colUse As Collection)
Dim tNetRes As NETRES2
Dim lngRet As Long
Dim lngHndEnum As Long
On Error Resume Next
With tNetRes
.lpRemoteName = p_strDomain
.dwDisplayType = 1
End With
lngRet = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, tNetRes, lngHndEnum)
If lngRet <> 0 Then ' check for ERROR_NO_NETWORK here!!!
MsgBox "Error getting computers on the LAN.", vbCritical, "Error"
Exit Sub
End If
.
.
.