Kenny Bones
Kenny Bones

Reputation: 5139

Vb.net - Display each network adapter, enabled or disabled

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

Upvotes: 1

Views: 8519

Answers (1)

Cody Gray
Cody Gray

Reputation: 245001

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:

A NetworkInterface array that contains objects that describe the available network interfaces, or an empty array if no interfaces are detected.

Upvotes: 2

Related Questions