detect if wlan is turned off

会有一股神秘感。 提交于 2019-12-02 06:25:12

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

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

MSDN NetworkInformation class

An example to get you started

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

Use the IsWiFiEnabled property of DeviceNetworkInformation class

You can refer to the How-To network information page if you need other network informations.

Regards.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!