Mike Petrichenko,谢谢你的提示。我找到了基于 CodePlex 提供的“wlanapi.dll”的解决方案:https ://archive.codeplex.com/?p=managedwifi将两个文件“Interop.cs”和“WlanApi.cs”添加到项目后,以下代码完成了这项工作
using NativeWifi;
using System.Runtime.InteropServices;
{
WlanClient client = new WlanClient();
foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
{
IntPtr radioStatePtr = new IntPtr(0L);
try
{
Wlan.WlanPhyRadioState radioState = new Wlan.WlanPhyRadioState();
radioState.dwPhyIndex = 0;
radioState.dot11HardwareRadioState = Wlan.Dot11RadioState.On;
radioState.dot11SoftwareRadioState = Wlan.Dot11RadioState.Off; //In this place we set WiFi to be enabled or disabled
radioStatePtr = Marshal.AllocHGlobal(Marshal.SizeOf(radioState));
Marshal.StructureToPtr(radioState, radioStatePtr, false);
Wlan.ThrowIfError(
Wlan.WlanSetInterface(
client.clientHandle,
wlanIface.InterfaceGuid,
Wlan.WlanIntfOpcode.RadioState,
(uint)Marshal.SizeOf(typeof(Wlan.WlanPhyRadioState)),
radioStatePtr,
IntPtr.Zero));
}
finally
{
if (radioStatePtr.ToInt64() != 0)
Marshal.FreeHGlobal(radioStatePtr);
}
}
}