【问题标题】:Getting wifi Signal strength获取 wifi 信号强度
【发布时间】:2013-09-12 07:29:49
【问题描述】:

有没有办法在 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 的

【问题讨论】:

标签: c# windows wifi


【解决方案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

【讨论】:

  • 你试过这个查询吗?我已经试过很久了,不记得错误了,但它从来没有用过,我看到很多人报告了同样的查询
  • FWIW,Windows 中有一个内置工具可让您运行 WMI 查询。要运行它,打开 cmd 窗口并输入 WBEMTEST
  • 5 年后,我被敦促这样做:在调试时,我发现一个异常,指出“不兼容”,简单粗暴。任何人都知道如何使用 .NET API 来实现这一点,而不是像 NativeWifi 这样有一天会失效的外部库。
猜你喜欢
  • 1970-01-01
  • 2013-10-17
  • 2014-07-26
  • 2012-07-08
  • 2013-08-26
  • 1970-01-01
  • 1970-01-01
  • 2013-09-20
  • 2014-03-01
相关资源
最近更新 更多