I was struggling with this and I just want to share my solution
(download managed wifi recommended above)
Add WlanApi.cs and Interop.cs to your project.
Add using NativeWifi.
In WlanApi.cs
change to:
public IntPtr clientHandle;
(You need the clientHandle. Not sure why it was set to private?)
Use this code:
string arg1 = "true"; //set to false if you want to turn it off.
arg1 = arg1.ToLower();
IntPtr radioStatePtr = new IntPtr(0L);
try
{
WlanClient wc = new WlanClient();
foreach (var iface in wc.Interfaces)
{
//WlanInterface
if(iface.InterfaceName.ToLower()=="wifi")
{
Wlan.WlanPhyRadioState radioState = new Wlan.WlanPhyRadioState();
radioState.dwPhyIndex = 0;
if(arg1=="true")
{
radioState.dot11HardwareRadioState = Wlan.Dot11RadioState.On;
radioState.dot11SoftwareRadioState = Wlan.Dot11RadioState.On;
}
else
{
radioState.dot11HardwareRadioState = Wlan.Dot11RadioState.Off;
radioState.dot11SoftwareRadioState = Wlan.Dot11RadioState.Off;
}
radioStatePtr = Marshal.AllocHGlobal(Marshal.SizeOf(radioState));
Marshal.StructureToPtr(radioState, radioStatePtr, false);
Wlan.WlanSetInterface(wc.clientHandle, iface.InterfaceGuid, Wlan.WlanIntfOpcode.RadioState, (uint)Marshal.SizeOf(typeof(Wlan.WlanPhyRadioState)), radioStatePtr, IntPtr.Zero);
}
}
}
finally
{
if (radioStatePtr.ToInt64() != 0)
Marshal.FreeHGlobal(radioStatePtr);
}
Good luck :)