关闭

c#Windows Mobile WiFi开启和关闭

标签: wifiwindows mobilec#
309人阅读 评论(0) 收藏 举报
分类:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.Runtime.InteropServices;

namespace StationInspection.Util
{
    class WiFiHelper
    {
        [DllImport("coredll.dll", SetLastError = true)]
        public static extern int SetDevicePower(string pvDevice, int dwDeviceFlags, DevicePowerState DeviceState);

        public enum DevicePowerState : int
        {
            Unspecified = -1,
            D0 = 0, // Full On: full power, full functionality 
            D1, // Low Power On: fully functional at low power/performance 
            D2, // Standby: partially powered with automatic wake 
            D3, // Sleep: partially powered with device initiated wake 
            D4, // Off: unpowered 
        }

        public const int POWER_NAME = 0x00000001;

        public static string FindDriverKey()
        {
            string ret = string.Empty;

            //#define PMCLASS_NDIS_MINIPORT           TEXT("{98C5250D-C29A-4985-AE5F-AFE5367E5006}") 
            //(From "c:\Program Files (x86)\Windows Mobile 6 SDK\PocketPC\Include\Armv4i\pm.h") 
            string WiFiDriverClass = "{98C5250D-C29A-4985-AE5F-AFE5367E5006}";

            foreach (string tmp in Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\Power\\State", false).GetValueNames())
            {
                if (tmp.Contains(WiFiDriverClass))
                {
                    ret = tmp;
                    break;
                }
            }

            return ret;
        }

    }
}

//开启
string driver = WiFi.FindDriverKey();
            WiFi.SetDevicePower(driver, WiFi.POWER_NAME, WiFi.DevicePowerState.D0);

//关闭
string driver = WiFi.FindDriverKey();
            WiFi.SetDevicePower(driver, WiFi.POWER_NAME, WiFi.DevicePowerState.D4);

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:329次
    • 积分:13
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档