
Newer versions of Windows have an 'Airplane mode' toggle like cell phones that turns off all the radios, which on a desktop might only be WiFi, but if you have a Surface tablet would also Bluetooth and possibly 4G. Microsoft doesn't really like you interacting with these yourself; it documents interfaces like IRadioInstance; but only for radio providers-- it doesn't disclose how you might go about obtaining them as a consumer to toggle them on your own.
Airplane mode is even more opaque. Disabling all the radios individually isn't enough for the little airplane to show up and the Settings indicate Airplane Mode is on. Turns out they have a very simple COM object to turn it on and off, but it's completely undocumented. user3296587 on StackOverflow reverse engineered it and posted some C++ code, which I first brought to twinBASIC and now to VB6 in the latest release of oleexp. VB6/tB of course make using COM interfaces a breeze, so toggling airplane mode is just a few simple lines:
Code:
Dim pRM As New RadioManagementAPI
Dim pbOld As Long, arg2 As Long, arg3 As Long
pRM.GetSystemRadioState pbOld, arg2, arg2
pRM.SetSystemRadioState IIf(pbOld, 0, 1)
Requirements
VB6: A reference to oleexp.tlb, v6.5 or higher. IDE only, not needed for compiled exe.
twinBASIC: oleexp.tlb is 32bit only, so while you can use it, it's better to use Windows Development Library for twinBASIC (WinDevLib) which also supports 64bit and covers 100% of oleexp.tlb (+5500 more APIs). Added via the Package Manager (details).
Interacting with individual radios
If you want to list, query, and toggle system radios on an individual basis, check out my full RadioMan project. It's only for twinBASIC right now but would be trivial to port to VB6; oleexp has all the required interfaces. It's also very small thanks to these high level interfaces; the whole thing is under 500 lines (excluding the interface defs in WinDevLib/oleexp).
