以编程方式打开或关闭飞行模式 Windows [英] Programmatically turn airplane mode on or off Windows

查看:47
本文介绍了以编程方式打开或关闭飞行模式 Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,需要在 Windows 上打开或关闭飞行模式.我看过这个问题,但答案只能得到状态,或者说你不能为 Metro 应用做这样的事情.我制作现代/地铁应用程序,所以我不需要担心应用程序沙盒.

I am writing an app where I need to turn airplane mode on or off on windows. I have seen this question, but the answers only get the status, or say you cannot do such a thing for Metro apps. I am not making a modern/metro app, so I don't need to worry about application sandboxing.

有没有打开/关闭飞行模式的api,我应该如何使用它?

Is there an api to turn Airplane mode on/off, and how should I use it?

在我的用例中,我知道我可以控制它,并且用户可以接受.

另外,我发现 这个 msdn 问题,摘录如下:

Also, I found this msdn question with the following excerpt:

Windows 8(build 8250),我可以在 Metro Style Network Setting UI 中打开/关闭飞行模式.

Windows 8(build 8250), I can turn on / off airplane mode in Metro Style Network Setting UI.

如何以编程方式执行此操作?

How to do this programmatically?

  1. Microsoft 为无线单选按钮定义了 HID 使用代码(用法:0xC6).

  1. Microsoft defined HID Usage code for Wireless Radio Button (Usage: 0xC6).

问题:无线电按钮是否有一些虚拟键码?如果是这样,应用程序可以通过 Keybd_event 发送此键码.

Question: Is there some virtual key code for Wireless Radio Button? If so, Application can send this keycode by Keybd_event.

WLANAPI.dll 导出 API WlanStoreRadioStateOnEnteringAirPlaneMode ,但没​​有该 API 的任何文档.

WLANAPI.dll export the API WlanStoreRadioStateOnEnteringAirPlaneMode , but there are no any document for this API.

问题:您能提供详细信息吗?是用来控制飞行模式的,这个API怎么调用?

Question: Can you provide detail information? Is it used to control Air Plane Mode, How to call this API?

显然(给出答案的摘要),可以使用 MobileBroadbandRadioState 枚举检查飞行模式的状态.

So apparently (to give a summery of the answer), one can check the state of Airplane mode using the MobileBroadbandRadioState enum.

HID 路由可能是一种可能性 文档.显然这是一个是否可以将代码0xc6发送到kbd_event的问题.

The HID route may be a possibility docs. Apparently it is a question of whether one can send the code 0xc6 to kbd_event.

显然有一个名为 Network Flyout 的窗口,我正在考虑枚举孩子以找到开关,但我没有取得太大的成功.我将不得不使用更多的 Spy++ 来找出答案.

Apparently there is a window called Network Flyout and I was thinking of enumerating the children to find the switch, but I haven't had much success. I'll have to use Spy++ some more to find out.

推荐答案

以下所有内容都是我通过逆向工程发现的.

All of the following I discovered myself via reverse engineering.

Windows 内部用于获取/设置飞行模式的内部 API 使用对RMsvc"的 COM 调用.服务(位于RMApi.dll"中).该服务正在导出一个工厂和接口,其中包含获取/设置飞行模式的功能:

The internal API used internally by windows to get/set Airplane mode makes use of COM calls to "RMsvc" service (which is located in "RMApi.dll"). That service is exporting a factory and interface which contains functions to get/set flight mode:

#include <Windows.h>
#include <assert.h>
#include <stdio.h>

static GUID const CLSID_RadioManagementAPI = { 0x581333f6, 0x28db, 0x41be, { 0xbc, 0x7a, 0xff, 0x20, 0x1f, 0x12, 0xf3, 0xf6 } };
static GUID const CID_IRadioManager        = { 0xdb3afbfb, 0x08e6, 0x46c6, { 0xaa, 0x70, 0xbf, 0x9a, 0x34, 0xc3, 0x0a, 0xb7 } };

typedef IUnknown IUIRadioInstanceCollection; /* Didn't bother rev-engineering this one... */
typedef DWORD _RADIO_CHANGE_REASON;

typedef struct IRadioManagerVtbl IRadioManagerVtbl;
typedef struct IRadioManager {
    IRadioManagerVtbl *lpVtbl;
} IRadioManager;
struct IRadioManagerVtbl {
    /* IUnknown */
    HRESULT (STDMETHODCALLTYPE *QueryInterface)(IRadioManager *This, GUID const *riid, LPVOID *ppvObj);
    ULONG (STDMETHODCALLTYPE *AddRef)(IRadioManager *This);
    ULONG (STDMETHODCALLTYPE *Release)(IRadioManager *This);
    /* IRadioManager (aka. `CUIRadioManager') */
    HRESULT (STDMETHODCALLTYPE *IsRMSupported)(IRadioManager *This, DWORD *pdwState);
    HRESULT (STDMETHODCALLTYPE *GetUIRadioInstances)(IRadioManager *This, IUIRadioInstanceCollection **param_1);
    HRESULT (STDMETHODCALLTYPE *GetSystemRadioState)(IRadioManager *This, int *pbEnabled, int *param_2, _RADIO_CHANGE_REASON *param_3);
    HRESULT (STDMETHODCALLTYPE *SetSystemRadioState)(IRadioManager *This, int bEnabled);
    HRESULT (STDMETHODCALLTYPE *Refresh)(IRadioManager *This);
    HRESULT (STDMETHODCALLTYPE *OnHardwareSliderChange)(IRadioManager *This, int param_1, int param_2);
};

int main() {
    HRESULT hr;
    IRadioManager *irm;
    hr = CoInitialize(NULL);
    assert(!FAILED(hr));
    irm = NULL;
    hr = CoCreateInstance(&CLSID_RadioManagementAPI, NULL, 4,
                          &CID_IRadioManager, (void **)&irm);
    assert(!FAILED(hr) && irm);
    int bOldMode, b;
    _RADIO_CHANGE_REASON c;
    hr = irm->lpVtbl->GetSystemRadioState(irm, &bOldMode, &b, &c);
    assert(!FAILED(hr));
    printf("Old flight-mode state was: %s\n", bOldMode == 0 ? "on" : "off");
    /* Set flight mode to the opposite state. */
    hr = irm->lpVtbl->SetSystemRadioState(irm, bOldMode == 0 ? 1 : 0);
    assert(!FAILED(hr));
    irm->lpVtbl->Release(irm);
    CoUninitialize();
    return 0;
}

这篇关于以编程方式打开或关闭飞行模式 Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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