我为此苦苦挣扎,我只想分享我的解决方案
(下载上面推荐的托管 wifi)将 WlanApi.cs 和 Interop.cs 添加到您的项目中。使用 NativeWifi 添加。
在 WlanApi.cs 中更改为: public IntPtr clientHandle; (您需要 clientHandle。不知道为什么它被设置为私有?)
使用此代码:
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);
}
祝你好运 :)