3

I'm using ManagedWifi in my C# application. The application will take control and connect to a designated SSID. Right now I'm trying to handle all possible errors, especially this. At the moment the program can't tell if a wireless adapter is turned on / or even exists at all. The ManagedWifi code goes on as per normal, and did not throw any exception at all. Any help would be appreciated, thanks.

Zekareisoujin
  • 465
  • 1
  • 5
  • 19

2 Answers2

4

The WLAN API is your friend. In particular, see the example in the WlanQueryInterface documentation. Note that many laptops have an on/off switch for the wifi adapter, and in many of these the adapter will not be visible to windows at all when this switch is off.

I know that WMI can also be used to do some WIFI stuff, but I'm not sure if it can enumerate adapters and discover their properties the way that the WLAN api can.

Edited to add: Be aware of the existence of the Windows 7 Virtual Adapter, it tripped me up writing my wifi control application when I first encountered it.

Community
  • 1
  • 1
Jim In Texas
  • 1,524
  • 4
  • 20
  • 31
  • I queried for WLAN_RADIO_STATE (WlanClient.WlanInterface.RadioState in ManagedWifi), and I was able to get an indicator whether the wireless adapter is turned on or off by checking the states of PhyRadioState[0].dot11SoftwareRadioState and PhyRadioState[0].dot11HardwareRadioState (WlanInterface.RadioState.PhyRadioState[0].dot11SoftwareRadioState and WlanInterface.RadioState.PhyRadioState[0].dot11HardwareRadioState in C# ManagedWIfi). Notes that we have to check both hardware and software, since in laptop, the physical switch is hardware switch and the shortcut (usually Fn+F2 is software switch – Zekareisoujin Jul 26 '11 at 04:37
  • You can update your answer to provide more information, and give this question a vote up to help those who need this question =D. – Zekareisoujin Jul 26 '11 at 04:38
0

WMI is probably the best way to query the information you're looking for

Ana Betts
  • 73,868
  • 16
  • 141
  • 209