检查Windows 10中的以太网连接 [英] Check ethernet connection in windows 10
本文介绍了检查Windows 10中的以太网连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用以下功能来确定运行应用程序的计算机是否通过以太网连接到LAN。这在Windows 7中工作正常但在Windows 10中不起作用。即使机器实际上通过以太网连接到LAN,它也找不到以太网连接。
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.
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
我有什么试过:
我在网上搜索了与VB.Net,Windows 10&
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.
推荐答案
显然,微软在发布的W10时略微改变了网络适配器的适配器命名约定。适应W7& W10,我修改了原来的功能如下:
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:
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
这篇关于检查Windows 10中的以太网连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文