Vb.net - 显示每个网络适配器,启用或禁用
我正在尝试显示运行此应用程序的计算机上的网络适配器。 为此,我希望能够显示所有网络适配器,无论它们处于哪种状态。 然后我希望能够通过按下按钮来启用和禁用适配器。
我尝试过使用 System.Net.NetworkInformation,但似乎它只包含活动的信息。
' NETWORK ADAPTERS
' Create label
Dim LabelNetworkAdapter As New Label
Dim old As Padding = LabelNetworkAdapter.Margin
LabelNetworkAdapter.Margin = New Padding(old.Left, 8, old.Right, old.Bottom)
' CreateButton
Dim BtnConnectButton As New Button
BtnConnectButton.Height = 23
BtnConnectButton.Width = 60
For Each nic As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()
Dim strText As String = nic.Description.ToString
TableLayoutPanel_Nettverkskort.Controls.Add(LabelNetworkAdapter)
LabelNetworkAdapter.Text = strText
TableLayoutPanel_Nettverkskort.Controls.Add(BtnConnectButton)
BtnConnectButton.Text = "Koble fra"
Exit For
Next
I'm trying to display the network adapters on the computer running this application.
For that I want to be able to display all network adapters, no matter which status they have.
Then I want to be able to enable and disable the adapters by pushing a button.
I've tried using System.Net.NetworkInformation
, but it seems as though it only contains the one that's active.
' NETWORK ADAPTERS
' Create label
Dim LabelNetworkAdapter As New Label
Dim old As Padding = LabelNetworkAdapter.Margin
LabelNetworkAdapter.Margin = New Padding(old.Left, 8, old.Right, old.Bottom)
' CreateButton
Dim BtnConnectButton As New Button
BtnConnectButton.Height = 23
BtnConnectButton.Width = 60
For Each nic As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()
Dim strText As String = nic.Description.ToString
TableLayoutPanel_Nettverkskort.Controls.Add(LabelNetworkAdapter)
LabelNetworkAdapter.Text = strText
TableLayoutPanel_Nettverkskort.Controls.Add(BtnConnectButton)
BtnConnectButton.Text = "Koble fra"
Exit For
Next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你想做的事是不可能的。当您禁用网络接口时,操作系统会对应用程序隐藏它。这是有道理的,因为您实际上无法使用它。您看到它的唯一方法是在 shell 的“网上邻居”文件夹中(或者他们现在决定称呼它的任何名称)。
MSDN 上的此错误报告似乎恰当地描述您的问题。它被“按设计”关闭。
文档甚至解释了返回值为:
What you're trying to do is not possible. When you disable a network interface, the operating system hides it from applications. Which makes sense, since you can't actually use it. The only way you're going to see it is in the shell's "My Network Places" folder (or whatever they've decided to call it now).
This bug report on MSDN seems to aptly describe your problem. It was closed as "by design".
The documentation even explains that the return value is: