Reputation: 3345
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:
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
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