2

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

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Aster Veigas
  • 866
  • 3
  • 13
  • 34
  • 2
    Is this what you are looking for? http://stackoverflow.com/questions/1686715/c-sharp-how-do-i-access-the-wlan-signal-strength-and-others – Florin Petriuc Sep 12 '13 at 07:35
  • I should be adding a reference of NativeWifi isnt it? – Aster Veigas Sep 12 '13 at 07:37
  • Got it @FlorinPetriuc. The link is http://managedwifi.codeplex.com/ and this post on stackover flow explains how to use it http://stackoverflow.com/questions/6485570/c-sharp-the-type-or-namespace-nativewifi-could-not-be-found – Aster Veigas Sep 12 '13 at 07:52
  • 1
    I get exception :An exception of type 'System.ComponentModel.Win32Exception' occurred.Additional information: The service has not been started. When I run this on a VM.VM's dont support this API? – Aster Veigas Sep 12 '13 at 11:10

1 Answers1

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

Aby
  • 1,916
  • 1
  • 12
  • 18
  • 2
    Have you tried this query? I had tried this long back don't remember the error but it never works and I had seen many people report the same about the query – Aster Veigas Sep 12 '13 at 11:54
  • FWIW, there's a built-in tool in Windows that lets you run WMI queries. to run it, open cmd window and type WBEMTEST – FuzzyAmi May 11 '14 at 10:28
  • 5 years later I'm urged to do so:, when debugging I find an Exception that states "Incompatible", plain and bold. Anyone knows how can this be achieved using the .NET API's, not external libraries that someday get defunct the likes of NativeWifi. – digitai Nov 09 '17 at 17:43