简体   繁体   English

列出C#中的Windows网络连接/配置文件

[英]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#? 有人能指点我一个班级列出在C#中安装在Windows机器(XP,Vista,7,8,8.1)上的当前网络配置文件吗?

I basically want a list of the following along with their connection status: 我基本上想要一个以下列表及其连接状态:

Windows网络连接

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. 我已经看过NetworkInterface.GetAllNetworkInterfaces()函数,但显然只返回物理适配器,我正在寻找的是网络配置文件。

You can do this by using the Network List Manager API which enables applications to retrieve the list of available network connections. 您可以使用网络列表管理器API执行此操作,该API使应用程序能够检索可用网络连接列表。 The Windows API Code Pack for .Net wraps this API so that it can be used easily by managed applications. .Net的Windows API代码包包装此API,以便托管应用程序可以轻松使用它。 Add the NuGet package 添加NuGet包

Windows API Code Pack - Core Windows API代码包 - 核心

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"));
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM