C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

C# Source Code


Welcome to Dream.In.Code
Become a C# Expert!

Join 300,482 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,767 people online right now. Registration is fast and FREE... Join Now!





Get signal strength of WI-FI adapters

This is a snippet used to retrieve the WI-FI signal strength of all WI-FI cards attached to your system. Can be used to tell if you are near a WI-FI connection

Submitted By: PsychoCoder
Actions:
Rating:
Views: 4,279

Language: C#

Last Modified: January 16, 2009
Instructions: Need a reference to the System.Management Namespace

Snippet


  1. /// <summary>
  2. /// method for retrieving the signal strength of all WI-FI adapters
  3. /// </summary>
  4. /// <returns></returns>
  5. public static string GetWIFISignalStrength()
  6. {
  7.     try
  8.     {
  9.         ObjectQuery query = new ObjectQuery("SELECT * FROM MSNdis_80211_ReceivedSignalStrength Where active = true");
  10.         ManagementScope scope = new ManagementScope("root\\wmi");
  11.         ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
  12.         string result = "";
  13.         foreach (ManagementObject obj in searcher.Get())
  14.         {
  15.             if ((bool)obj["Active"] == true)
  16.             {
  17.                 result += (string)obj["Ndis80211ReceivedSignalStrength"].ToString() + Environment.NewLine;
  18.             }
  19.         }
  20.         if (result == "")
  21.         {
  22.             result = "No active WI-FI adapters found!";
  23.         }
  24.  
  25.         return result.Trim();
  26.     }
  27.     catch (Exception ex)
  28.     {
  29.         MessageBox.Show(ex.Message, "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  30.         return string.Empty;
  31.     }
  32. }

Copy & Paste


Comments


christyyim 2008-09-22 06:55:15

hihi, i'm a newbie for programming. but now i have to write a code to extract the signal strength from the wi-fi adapter. and i found this webpage. i wonder how this code works? cos it seems like call a lot functions. but i dunno where is the source code for those function. can anyone give me some clues. thanks

DerekR 2009-01-16 08:18:14

Small but important typo on line 17 Ndis80211ReceivedSingnalStrength should read Ndis80211ReceivedSignalStrength.

PsychoCoder 2009-01-16 09:24:39

Thanks for pointing that out DerekR, fixed :)

ahussain 2009-02-03 06:03:50

Hi, I need to get Wi-Fi signal Strength in my coding plz any one help me how can i get this. Cheers..

ahussain 2009-02-09 07:12:25

Hi every one in forum I tried this piece of code but it did't work please let me know how can i run this code because its output is "SYSTEM NOT SUPPORTED" please help me to run and get signal strenght Thanks


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month