有没有办法在C#中获得wifi信号强度?目前我正在通过
获得相同的结果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
答案 0 :(得分:1)
为什么不使用WMI查询以干净的方式获取它?
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/en-US/34a66ee5-34f8-473d-b6f2-830a14e2300b/get-signal-strength-in-c