The other day, I had a need to programmatically figure out what the name of the Wifi network I was connected to. Thought I’d share the code:

ManagementClass mc = new ManagementClass(”root\\WMI”, “MSNdis_80211_ServiceSetIdentifier”, null);
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
string wlanCard = (string)mo["InstanceName"];
bool active = (bool)mo["Active"];
byte[] ssid = (byte[])mo["Ndis80211SsId"];
string ssidString = Encoding.ASCII.GetString(ssid);
Console.WriteLine(”{0}\r\n{1}\r\n{2}”, wlanCard, active, ssidString);
Console.WriteLine();
}

WMI Rules. :)



No Comments

No comments yet.

Sorry, the comment form is closed at this time.