Getting wifi Signal strength

2019-02-19 23:32发布

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

标签: c# windows wifi
1条回答
冷血范
2楼-- · 2019-02-20 00:28

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

查看更多
登录 后发表回答