Get Battery Info without WMI

吃可爱长大的小学妹 提交于 2019-12-06 10:06:11

To get those particular values you need to do separate queries against different classes instead of win32_battery.

DesignCapacity can be queried from BatteryStaticData

FullChargeCacity can be queried from BatteryFullChargedCapacity

You'll need to use a different scope in the code also for the query. These classes are found in root/WMI instead of root/cimv2

string scope = "root/WMI";
string query = "SELECT DesignedCapacity FROM BatteryStaticData";

ManagementObjectSearcher batteriesQuery = new ManagementObjectSearcher(scope, query);

ManagementObjectCollection batteries = batteriesQuery.Get();

foreach (ManagementObject battery in batteries)
{
    if (battery != null)
    {
        foreach (var property in battery.Properties)
        {
            Console.Log("Property name: " + property.Name + " Property value: " + property.Value);
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!