mikedavies-dev
mikedavies-dev

Reputation: 3345

List Windows network connections/profiles in C#

Can someone point me to a class to list the current network profiles installed on a Windows machine (XP,Vista,7,8,8.1) in C#?

I basically want a list of the following along with their connection status:

Windows network connections

I have had a look at the NetworkInterface.GetAllNetworkInterfaces() function but that obviously just returns the physical adapters, what I am looking for is the network profiles.

Upvotes: 3

Views: 2922

Answers (1)

stamhaney
stamhaney

Reputation: 1314

You can do this by using the Network List Manager API which enables applications to retrieve the list of available network connections. The Windows API Code Pack for .Net wraps this API so that it can be used easily by managed applications. Add the NuGet package

Windows API Code Pack - Core

Call the following function to list the network profiles:

public void ListNetworkProfiles()
{
    NetworkCollection nCollection = NetworkListManager.GetNetworks(NetworkConnectivityLevels.All);
    foreach (Network net in nCollection)
    {
        Console.WriteLine("Name: " + net.Name + " Status: " + (net.IsConnected ? "Connected" : "Not Connected"));
    }
}

Upvotes: 5

Related Questions