下面的这个函数从系统获取 WiFi 信号。它目前在我的表单上显示“0”(表示我假设的强连接)。我在公司网络上的工作场所 HP 上运行它的机器。它似乎没有外部 WiFi 按钮等。“0”是我得到的真实值还是需要在真正的无线设备上进行测试?
public static int GetSignalStrengthAsInt()
{
Int32 returnStrength = 0;
ManagementObjectSearcher searcher = null;
try
{
searcher = new ManagementObjectSearcher(
@"root\WMI",
@"select Ndis80211ReceivedSignalStrength
from MSNdis_80211_ReceivedSignalStrength
where active=true");
// Call the get in order to populate the collection
ManagementObjectCollection adapterObjects = searcher.Get();
// Loop though the management object and pull out the signal strength
foreach ( ManagementObject mo in adapterObjects )
{
returnStrength = Convert.ToInt32(
mo["Ndis80211ReceivedSignalStrength"].ToString());
break;
}
}
catch (Exception)
{
}
finally
{
if ( searcher != null )
{
searcher.Dispose();
}
}
return returnStrength;
}
returnStrength 目前正在文本框中显示。