惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tenable Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

博客园 - 和尚释然

AsyncTask原理 Android 模拟器截图 [原创]Android NDK开发之HelloWorld 附源码 Android NDK开发之环境搭建 [原创]深入了解Activity生命周期 附源码 [原创]关于Android Service的示例编程 附源码 [原创]Android Camera 开发之实现一 附源码 [原创]Android Camera 开发之前言 [原创]在Eclipse中手工安装SVN Plugin Android开发环境搭建四:新建一台Android Virtual Device Android开发环境搭建三:在Eclipse配置Android SDK Android开发环境搭建二:安装ADT[新版本ADT15.0] Android开发环境搭建一:安装Android JDK Java开发环境配置图解 用Reflector反编译 Mobile Winform程序 VS2005/VS2008英文版应用程序无法显示中文字符 深入讲解main()返回值研究 用VisualStudio2008汇编代码 发布MFC ActiveX控件并实现自动更新
Mobile WiFi的开启和关闭代码实现
和尚释然 · 2011-08-09 · via 博客园 - 和尚释然

2011-08-09 22:08  和尚释然  阅读(1171)  评论()    收藏  举报

目前我们公司移动设备大量出现发热发烫和电池不够用的问题,严重影响正常使用.网上查询了一下发现网络设备是一个耗电大户,加上我们公司的设备在每次系统重启后都会自动打开WiFi功能.这样就存在耗电和发烫的隐患,如果设备在WiFi开启状态下在进入一个有无线网络的领域就会自动匹配连接,这个过程是比较耗电的.所以今天就实现了通过一个小工具去关闭WiFi.操作WiFi主要通过以下两个方法:DevicePowerNotify;SetDevicePower.

要代码实现:

HRESULT WifiOn()
{    
    TCHAR WstrDeviceClass[128];
    BOOL ret = GetWIFIDeviceName(WstrDeviceClass);
    if(!ret) return ERROR_INVALID_GETWIFIDEVICENAME;    
    DevicePowerNotify(WstrDeviceClass, D0, POWER_NAME);
    return SetDevicePower( WstrDeviceClass, POWER_NAME, D0);    
}

HRESULT WifiOff()
{
    TCHAR WstrDeviceClass[128];
    BOOL ret = GetWIFIDeviceName(WstrDeviceClass);
    if(!ret) return ERROR_INVALID_GETWIFIDEVICENAME;    
    DevicePowerNotify(WstrDeviceClass, D4, POWER_NAME);    
    return SetDevicePower( WstrDeviceClass, POWER_NAME, D4);    
}

其中的WstrDeviceClass参数就是下面其中<DEVICE_NAME>就是适配器的名称。

HKEY_LOCAL_MACHINE / System / CurrentControlSet / Control / POWER /
State / {98C5250D-C29A-4985-AE5F-AFE5367E5006}\<DEVICE_NAME>

注:{98C5250D-C29A-4985-AE5F-AFE5367E5006}\<DEVICE_NAME>是键的名称,不是子父路径的关系。

将这个键的名称直接传给SetDevicePower的pvDevice参数即可。