且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测WLAN是否关闭

更新时间:2023-01-27 11:34:51

如果您正在寻找非8.1 Silverlight解决方案:

If you're looking for a Non 8.1 Silverlight solution:

您可以使用 Windows.Networking.Connectivity 命名空间进行查询。

You can use the Windows.Networking.Connectivity namespace to query this.

MSDN NetworkInformation类

一个入门示例

bool is_wifi_enabled = false;
Guid adapter_id = new Guid();

// get the list of connection profiles
// we need the adpater id for the wifi
foreach (var item in NetworkInformation.GetConnectionProfiles())
{

    // check if wifi
    if (item.IsWlanConnectionProfile)
    {
        // tag the adapter
        adapter_id = item.NetworkAdapter.NetworkAdapterId;
    }
}

// get all lan adapters (this most likely will be empty if wlan is disabled)
foreach (var item in NetworkInformation.GetLanIdentifiers())
{
    if (item.NetworkAdapterId == adapter_id)
    {
        is_wifi_enabled = true;
    }
}