spychu
spychu

Reputation: 113

Get Battery Info without WMI

Is there some way to obtain the battery DesignCapacity and FullChargeCpacity without WMI ? This values are not supported in WMI so I need to find other way to get them.

Or maybe somebody have better (easier) idea to get the wear level of battery in C#?

BTW I try to use it this way but just returned null

ManagementObjectSearcher query = 
        new ManagementObjectSearcher("SELECT DesignCapacity FROM Win32_Battery");

foreach (ManagementObject queryObj in query.Get())
{
    string dc = Convert.ToString(queryObj.GetPropertyValue("DesignCapacity"));
    label1.Text = dc + " mAh";
}

Thanks

Upvotes: 3

Views: 2351

Answers (1)

Joshua Hysong
Joshua Hysong

Reputation: 1072

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);
        }
    }
}

Upvotes: 3

Related Questions