也谈Windows Mobile中打开/关闭WIFI

看到Yonsm兄写的“Windows Mobile 中开关 WIFI 的“通用”代码”一文。
原文地址:http://www.yonsm.net/read.php?412

在我机器(586W 6.1)测试无效,研究后发现Yonsm兄的算法并不通用,至少在我机器上无效。
其实问题在于获取WIFI适配器的名称上。

搜索了遍注册表,终于找到了解决办法。
HKEY_LOCAL_MACHINE / System / CurrentControlSet / Control / POWER /
State / {98C5250D-C29A-4985-AE5F-AFE5367E5006}\<DEVICE_NAME>

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

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

附:C#实现代码!

string[] sNames = null;
            RegistryKey keyWlan 
= null;
            
try
            
{
                keyWlan 
= Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Power\State");
                sNames 
= keyWlan.GetValueNames();
            }

            
catch { }
            
finally
            
{
                
if (keyWlan != null) keyWlan.Close();
            }


            
foreach (string wl in sNames)
            
{
                
if (wl.StartsWith("{98C5250D-C29A-4985-AE5F-AFE5367E5006}\\"))
                
{
                    
//POWER_NAME = 0x00000001
                    SetDevicePower(wl0x00000001, open ? DevicePowerState.D0 : DevicePowerState.D4);
                    
break;
                }

            }
原文地址:https://www.cnblogs.com/mondol/p/1331421.html