如何在 Windows 中打开/关闭无线电? [英] How to turn wireless radio on/off in Windows?

查看:43
本文介绍了如何在 Windows 中打开/关闭无线电?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种 API 来以编程方式在 Windows 中打开和关闭无线电,就像以下 Windows 10 UI 元素一样:

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:

  • 需要打开/关闭 Wi-Fi、蓝牙或移动宽带
  • 适用于 Windows 7、8 和 10
  • 这不是电话
  • C#/.NET4.5 是理想的,但 C++/Win32 也可以

推荐答案

对于 Windows 10,您可以使用 Radio Manager API 来控制不同的无线电状态.您可以在此处找到完整的示例应用(均C# 和 C++).

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++).

首先,您需要访问所有系统无线电.这必须在 UI 线程中调用:

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

这篇关于如何在 Windows 中打开/关闭无线电?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆