0

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?

Community
  • 1
  • 1
Mahesh
  • 705
  • 3
  • 8
  • 17
  • 1
    What OS is running on your device? The code and link are about Windows 7 and not Compact Framework. For CF use OpenNetCF (ie https://www.opennetcf.com/library/sdf/html/e7233249-6758-6bec-b816-c2c0ad7f46b5.htm) – josef Apr 09 '14 at 17:51
  • Hey @josef ... Thanks for your reply. I'm looking for solution in windows7 itself in C#. – Mahesh Apr 10 '14 at 16:06
  • So why doesn't your code match the link you provided that does work? – Erik Philips Apr 10 '14 at 16:19
  • @ErikPhilips I Used the same code only ... Error prints to debug nothing much diference – Mahesh Apr 11 '14 at 05:18

0 Answers0