2013-11-14 63 views
2

我使用Managed Wifi來獲取Wifi適配器的無線電狀態。 如果實際上關閉收音機,我該如何打開收音機?如何打開實際關閉的Wifi適配器的無線電?

事情是這樣的:

WlanClient wlanClient = new WlanClient() 
var targetInterface = wlanClient.Interfaces.FirstOrDefault() 
if (targetInterface != null) 
{ 
    bool radioIsOff = targetInterface .RadioState.PhyRadioState[0].dot11SoftwareRadioState == Wlan.Dot11RadioState.Off; 
    if (radioIsOff) 
    { 
     // TODO 
    } 
} 

回答

3

我只是說這將WlanInterface類託管無線上網的API的:

 IntPtr radioStatePtr = new IntPtr(0L); 
     try 
     { 
      Wlan.WlanPhyRadioState radioState = new Wlan.WlanPhyRadioState(); 
      radioState.dwPhyIndex = 0; // TODO : can change ??? 
      radioState.dot11HardwareRadioState = Wlan.Dot11RadioState.On; // ignored in fact, according to http://msdn.microsoft.com/en-us/library/windows/desktop/ms706791(v=vs.85).aspx 
      radioState.dot11SoftwareRadioState = Wlan.Dot11RadioState.On; 

      radioStatePtr = Marshal.AllocHGlobal(Marshal.SizeOf(radioState)); 
      Marshal.StructureToPtr(radioState, radioStatePtr, false); 

      Wlan.ThrowIfError(
       Wlan.WlanSetInterface(
          client.clientHandle, 
          info.interfaceGuid, 
          Wlan.WlanIntfOpcode.RadioState, 
          (uint)Marshal.SizeOf(typeof(Wlan.WlanPhyRadioState)), 
          radioStatePtr, 
          IntPtr.Zero)); 
     } 
     finally 
     { 
      if (radioStatePtr.ToInt64() != 0) 
       Marshal.FreeHGlobal(radioStatePtr); 
     } 

測試在Win 7