C# 获取wifi信号强度

C# 获取wifi信号强度,c#,windows,wifi,C#,Windows,Wifi,有没有办法在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.Us

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

为什么不使用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);
}
更多信息请参见此。

这就是您要找的吗?我应该添加一个NativeWifi的参考,不是吗?明白了@Florinpetric。链接为,此关于stackover flow的帖子解释了如何使用它。我收到异常:发生了类型为“System.ComponentModel.Win32Exception”的异常。其他信息:服务尚未启动。当我在VM上运行此操作时。VM不支持此API?您尝试过此查询吗?我已经尝试了这么长时间,不记得错误,但它从来没有工作,我看到许多人报告同样的关于QueryWiw,有一个内置的工具在Windows中,让您运行WMI查询。要运行它,请打开cmd窗口并在5年后键入WBEMTEST5:,当调试时,我发现一个异常状态为“不兼容”,简单且粗体。任何人都知道如何使用.NETAPI来实现这一点,而不是像NativeWifi这样的外部库,因为它们终有一天会消失。