?
Solved

check Lan Status

Posted on 2010-09-14
3
Medium Priority
?
619 Views
Last Modified: 2012-06-27
Hi,

I have 2 Lan cables connectted to my local PC, is there a VB code to dectect if one or both of them are disconnected?
0
Comment
Question by:csharp_learner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Expert Comment

by:VBClassicGuy
ID: 33672672
Function HasConnectivity() As Boolean
        Dim hostInfo As System.Net.IPHostEntry
        Try 'to look for the logon server
            Dim sServer As String = Environment.GetEnvironmentVariable("logonserver")
            hostInfo = System.Net.Dns.GetHostByName(sServer.Remove(0, 2))
            Return True
        Catch 'theres no network connection
            Return False
        End Try
    End Function
0
 

Author Comment

by:csharp_learner
ID: 33678788
It hit an error "User-defined type not defined"
on the line
Dim hostInfo As System.Net.IPHostEntry
0
 
LVL 6

Accepted Solution

by:
PJBX earned 1400 total points
ID: 33709527
I think you're getting that error because that is VB.NET and not VB 6. Try the following:
Const NETWORK_ALIVE_AOL = &H4
Const NETWORK_ALIVE_LAN = &H1
Const NETWORK_ALIVE_WAN = &H2
Private Declare Function IsNetworkAlive Lib "SENSAPI.DLL" (ByRef lpdwFlags As Long) As Long

Private Sub Form_Load()
'KPD-Team 2001
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim Ret As Long
If IsNetworkAlive(Ret) = 0 Then
MsgBox "The local system is not connected to a network!"
Else
MsgBox "The local system is connected to a " + IIf(Ret = NETWORK_ALIVE_AOL, "AOL", IIf(Ret = NETWORK_ALIVE_LAN, "LAN", "WAN")) + " network!"
End If
End Sub
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question