Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been using the following function to determine if the machine that the application is running on is connected to the LAN via Ethernet. This works fine in Windows 7 but does not work in Windows 10. It does not find the Ethernet connection even though the machine is actually connected to the LAN via Ethernet.

VB
Public Function CheckEthernetLANConnection() As Boolean
    ' check to determine if the ethernet LAN is "up" (i.e. hardwire connection)
    CheckEthernetLANConnection = False
    Dim adapters As System.Net.NetworkInformation.NetworkInterface() = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
    For i As Short = 0 To adapters.Length - 1 Step 1
        If adapters(i).Name = "Local Area Connection" Then
            If adapters(i).OperationalStatus = Net.NetworkInformation.OperationalStatus.Up Then
                CheckEthernetLANConnection = True
                Exit For
            End If
        End If
    Next i
End Function


What I have tried:

I searched on the web for problems associated with VB.Net, Windows 10 & the
System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
class. I could not find anything.
Posted
Updated 14-Oct-17 9:39am
v2
Comments
phil.o 14-Oct-17 14:07pm    
Chances are, Windows 10 Ethernet connections are not named "Local Area Connection" by default.
When you debug this piece of code, how many elements does the adapters variable hold? What are their names?
Kevin Brady 14-Oct-17 14:12pm    
I do not have Windows 10 the development PC I use. This is on a client PC. Making troubleshooting all the more difficult. None the less, I will try to insert some code the determine what the adapter names are.
Kevin Brady 14-Oct-17 14:29pm    
This is a list of what I found.
Ethernet
Local Area Connection* 4
Ethernet 2
Wi-Fi
Bluetooth Network Connection
Loopback Pseudo-Interface 1

So now the question is do I key on "Local Area Connection* 4" or "Ethernet" or "Ethernet 2"?

1 solution

Apparently Microsoft slightly changed the adapter naming conventions for network adapters when the released W10. To accommodate W7 & W10, i have modified the original function as follows:

VB
Public Function CheckEthernetLANConnection() As Boolean
    ' check to determine if the ethernet LAN is "up" (i.e. hardwire connection)
    CheckEthernetLANConnection = False
    Dim adapters As System.Net.NetworkInformation.NetworkInterface() = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()

    For i As Short = 0 To adapters.Length - 1 Step 1
        Dim aStr As String = adapters(i).Name
        If aStr.Contains("Local Area Conn") = True Then
            If adapters(i).OperationalStatus = Net.NetworkInformation.OperationalStatus.Up Then
                CheckEthernetLANConnection = True
                Exit For
            End If
        End If

        If aStr.Contains("Ether") = True Then
            If adapters(i).OperationalStatus = Net.NetworkInformation.OperationalStatus.Up Then
                CheckEthernetLANConnection = True
                Exit For
            End If
        End If

    Next i

End Function
 
Share this answer
 
v2
Comments
phil.o 14-Oct-17 16:18pm    
Thanks for sharing your solution. I slightly modified your post to add the "vb" type to the pre tag for a better code readability.
Kevin Brady 14-Oct-17 17:34pm    
Thanks for help in prodding me to find a solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900