How to turn wireless radio on/off in Windows? [closed]

徘徊边缘 提交于 2019-12-11 13:28:42

问题


I'm looking for an API to programmatically toggle a wireless radio on and off in Windows, just like the following Windows 10 UI element does:

  • Need to toggle on/off Wi-Fi, Bluetooth, or mobile broadband
  • For Windows 7, 8 and 10
  • This is NOT a phone
  • C#/.NET4.5 would be ideal, but C++/Win32 would work too

回答1:


For Windows 10, you can use the Radio Manager APIs to control different radio states. You can find the full sample apps here (both C# and C++).

First you need to get access to all of the system radios. This must be called in a UI thread:

var accessLevel = await Radio.RequestAccessAsync();

Then, you can find all radios on the system (the sample describes other ways to access the radios):

var radios = await Radio.GetRadiosAsync();

Given a radio object, you can then change state by the following:

Radio radio = SOME_RADIO;
radio.StateChanged = Radio_StateChangedCallback; // Called when the radio state completes the change
radio.SetStateAsync(RadioState.On); // Or RadioState.Off



回答2:


So in general what you need to do is to enumerate the network adapters (filter out Wireless, Bluetooth and Mobile Broadband) and toggle their state?

No wonders that there are 3 close votes since SO is full of related questions and answers:

  • This demonstrates C# + WMI
  • This demonstrates C++ + WINAPI Device Installation API

One of those should be a fair starting point to put together what you need.




回答3:


Well I know you can manipulate the wireless connection with

netsh interface set interface name="Local Area Connection" via cmd line.

So maybe in c# you could do a Process.Start("netsh", "set name=\"Local Area Connection\""); to change the wifi settings. I'm sure you could download a bluetooth cmd line utility and do something similar with that.

I'll be able to test later when I get on my windows machine, but I can't right now, hopefully this helps.



来源:https://stackoverflow.com/questions/37734995/how-to-turn-wireless-radio-on-off-in-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!