示例#1
0
        public static string GetPowerType()
        {
            /*WMIService wmi = new WMIService();
             * ManagementObjectCollection collection = wmi.getObject("SELECT * FROM Win32_Battery");
             * string result = "";
             * foreach (ManagementObject obj in collection)
             * {
             *  result += obj["BatteryStatus"];
             * }
             * if (result == "1" || result == "3" || result == "4" || result == "5" || result == "11")
             *  return "Battery";
             * if (result == "2" || result == "6" || result == "7" || result == "8" || result == "9")
             *  return "AC";
             * else
             *  return "Unknown";*/
            SYSTEM_BATTERY_STATE batteryState = GetSystemBatteryStateStruct();

            if (batteryState.AcOnLine == true)
            {
                return("AC");
            }
            else
            {
                return("Battery");
            }
        }
示例#2
0
        public static string GetChargeLevel()
        {
            /*WMIService wmi = new WMIService();
             * ManagementObjectCollection collection = wmi.getObject("SELECT * FROM Win32_Battery");
             * string result = "";
             * foreach (ManagementObject obj in collection)
             * {
             *  result += obj["EstimatedChargeRemaining"];
             * }
             * return result;*/
            SYSTEM_BATTERY_STATE batteryState = GetSystemBatteryStateStruct();
            double result = batteryState.RemainingCapacity * 100 / batteryState.MaxCapacity;

            return(result.ToString());
        }