.Net WiFi Programming

free wifiSome time ago I was asked to write some code to

  1. detect if a user had saved a connection to an Open/Public Wifi point, and
  2. delete it if it exists.

The code had to work on Windows 7, so using the Wi-Fi Direct feature wasn’t available to me.

I could do this using the Native WiFi API, except that doing that from .Net isn’t easy.

So I used the managedwifi wrapper which Monfort Engineering developed and made open source.

Everything worked well except …

The code would occasionally fail.  Much reading of documentation, and lots of head scratching happened.  This was the answer:

“All wireless LAN functions require an interface GUID for the wireless interface when performing profile operations. When a wireless interface is removed, its state is cleared from Wireless LAN Service (WLANSVC) and no profile operations are possible.”
WlanSetProfile function

What that means in practice:

  1. if the Wireless LAN Service is not running, then there is no WiFi running
  2. if the user has disabled the WiFi Adapter, then there is no WiFi to query.

So if 1 or 2 occurred, the code I wrote would fail.

The code to fix that was as simple as this:

Private Sub DeleteOpenWifi()
If wifi.Interfaces.Length = 0 Then
     Exit Sub
End If

How to Avoid Public WiFi Security Risks
About the Native Wifi API
Managed WiFi API (Codeplex)
Is there anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc?