How to get SSID and RSSI for Win7 using C#
Asked Answered
R

2

4

I am very new to Win7 and WMI. Please advice me where to see for active access point from WiFi and how to get ssid/rssi for each access point.

I have use:

ManagementClass mc = new ManagementClass("root\\WMI", "MSNdis_80211_ServiceSetIdentifier", null);          
ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(@"root\wmi","SELECT * FROM MSNdis_80211_BSSIList");

but I got 0 results. Is this class support Win7? Anybody can help?

Rodgerrodgers answered 25/2, 2010 at 4:8 Comment(0)
T
5

I had a similar problem where I needed to get the SSID of the currently connected Wifi network but didnt feel like creating a wrapper for the API due to its complexity so figured why not use netsh

        ProcessStartInfo info = new ProcessStartInfo("netsh", "wlan show interfaces");
        info.WorkingDirectory = @"%WINDIR%\system32";
        info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        info.CreateNoWindow = true;
        info.RedirectStandardOutput = true;
        info.UseShellExecute = false;
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo = info;
        proc.Start();

then you can just retrieve the output from proc.StandardOutput.ReadToEnd(); parse out what you want from the string:

"\r\n There is 1 interface on the system: \r\n\r\n
Name                   : Wireless Network Connection\r\n
Description            : Atheros AR9285 Wireless Network Adapter\r\n
GUID                   : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\r\n
Physical address       : xx:xx:xx:xx:xx:xx\r\n
State                  : connected\r\n
SSID                   : Dynex2\r\n
BSSID                  : xx:xx:xx:xx:xx:xx\r\n
Network type           : Infrastructure\r\n
Radio type             : 802.11g\r\n
Authentication         : WPA2-Personal\r\n
Cipher                 : CCMP\r\n
Connection mode        : Auto Connect\r\n
Channel                : 1\r\n
Receive rate (Mbps)    : 54\r\n
Transmit rate (Mbps)   : 54\r\n
Signal                 : 100% \r\n
Profile                : Dynex2 \r\n\r\n
Hosted network status  : Not available\r\n\r\n"

Much easier to parse a string than to write a wrapper for the API Hope this helps

Transfuse answered 2/1, 2012 at 4:57 Comment(1)
How to use it in Windows XP, ? I think command does not work in XP, Works in Winows 7Jeggar
V
0

Instead of WMI you can use the Managed Wifi API.

Check this question Get SSID of the wireless network I am connected to with C# .Net on Windows Vista

Some time a go i wrote an example using delphi-prism, is very similar to C#. http://theroadtodelphi.wordpress.com/2009/09/30/detecting-wifi-networks-using-delphi-prism/

Vicar answered 25/2, 2010 at 16:3 Comment(1)
Thanx RRUZ, Actually i already use managed wifi api but wlan function seem cannot be applied and return "The type or namespace name 'Wlan' could not be found (are you missing a using directive or an assembly reference?)". I'm using Visual Studio 2010 and Windows 7. Is there any features in Visual Studio 2010 can help to get SSID and RSSI from Windows 7.Rodgerrodgers

© 2022 - 2024 — McMap. All rights reserved.