I have requirement to turn off wireless radio using wlanapi in C#
.
Iam able to turn off the radio but not able to turn on.
Here is my code:
WLAN_PHY_RADIO_STATE wlan_intf_opcode_radio_state = new WLAN_PHY_RADIO_STATE();
wlan_intf_opcode_radio_state.dwPhyIndex = 0; // TODO : can change ???
wlan_intf_opcode_radio_state.dot11HardwareRadioState = DOT11_RADIO_STATE.dot11_radio_state_on;// ignored in fact, according to http://msdn.microsoft.com/en-us/library/windows/desktop/ms706791(v=vs.85).aspx
wlan_intf_opcode_radio_state.dot11SoftwareRadioState = DOT11_RADIO_STATE.dot11_radio_state_on;
radioStatePtr = Marshal.AllocHGlobal(Marshal.SizeOf(wlan_intf_opcode_radio_state));
Marshal.StructureToPtr(wlan_intf_opcode_radio_state, radioStatePtr, false);
if (WlanEnumInterfaces(handle, IntPtr.Zero,
out ppInterfaceList) == ERROR_SUCCESS)
{
interfaceList = new WLAN_INTERFACE_INFO_LIST(ppInterfaceList);
for (int i = 0; i < interfaceList.dwNumberofItems; i++)
{
Guid pInterfaceGuid = ((WLAN_INTERFACE_INFO)interfaceList.InterfaceInfo[0]).InterfaceGuid;
if (WlanSetInterface(handle, ref pInterfaceGuid, WLAN_INTF_OPCODE.wlan_intf_opcode_radio_state, dataSize, ref ptr, IntPtr.Zero) == ERROR_SUCCESS)
MessageBox.Show("yes");
else MessageBox.Show("Some Issue");
}
}
Definition :
[DllImport("wlanapi.dll", SetLastError = true)]
public static extern uint WlanSetInterface(IntPtr hClientHandle, ref Guid pInterfaceGuid, WLAN_INTF_OPCODE OpCode, uint dwDataSize, ref IntPtr pData, IntPtr pReserved);
Everything going smooth I mean wlansetinterface function returning ERROR_SUCCESS
but radio is not swithching on in my PC.please help where i missed ?
I fallowed How can I turn ON radio of a Wifi adapter that is actually OFF?