Getting wifi Signal strength

佐手、 提交于 2019-12-19 10:27:11

问题


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();

and then I get the wifi signal strength by reading the output. Is there a better way? Preferably using API's


回答1:


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

Please see this for more info. http://social.msdn.microsoft.com/Forums/en-US/34a66ee5-34f8-473d-b6f2-830a14e2300b/get-signal-strength-in-c



来源:https://stackoverflow.com/questions/18758097/getting-wifi-signal-strength

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