获取wifi信号强度 [英] Getting wifi Signal strength
本文介绍了获取wifi信号强度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在C#中获得wifi信号强度?目前我正在通过
Is there a way to get wifi signal strength in C#? Currently I'm getting the same through
Process proc = new Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "netsh";
proc.StartInfo.Arguments = "wlan show interfaces";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
,然后通过读取输出获得wifi信号强度.有没有更好的办法?最好使用API
and then I get the wifi signal strength by reading the output. Is there a better way? Preferably using API's
推荐答案
为什么不使用WMI查询以干净的方式获取它?
Why don't you use a WMI query to get it in a clean way ?
private double RetrieveSignalString()
{
double theSignalStrength = 0;
ConnectionOptions theConnectionOptions = new ConnectionOptions();
ManagementScope theManagementScope = new ManagementScope("root\\wmi");
ObjectQuery theObjectQuery = new ObjectQuery("SELECT * FROM MSNdis_80211_ReceivedSignalStrength WHERE active=true");
ManagementObjectSearcher theQuery = new ManagementObjectSearcher(theManagementScope, theObjectQuery);
try
{
//ManagementObjectCollection theResults = theQuery.Get();
foreach(ManagementObject currentObject in theQuery.Get())
{
theSignalStrength = theSignalStrength + Convert.ToDouble(currentObject["Ndis80211ReceivedSignalStrength"]);
}
}
catch (Exception e)
{
//handle
}
return Convert.ToDouble(theSignalStrength);
}
请参阅此以获取更多信息. http://social.msdn.microsoft.com/Forums/zh-CN/34a66ee5-34f8-473d-b6f2-830a14e2300b/get-signal-strength-in-c
Please see this for more info. http://social.msdn.microsoft.com/Forums/en-US/34a66ee5-34f8-473d-b6f2-830a14e2300b/get-signal-strength-in-c
这篇关于获取wifi信号强度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文