I am trying to create a C# Application that records the battery percentage over time, and to do that I have been trying to use the .NET WMI API. I looked on MSDN and found that there is a WMI class called CIM_Battery
, and confirmed its existence with wbemtest.exe
.
The only issue with this method is that apparently the CIM_Battery
class has no instances that I can read from.
I know of battery monitor software that successfully reads the battery percentage on my laptop, so I know it is possible on my laptop. Am I trying to use the wrong tool for the job?
Yes, you are doing it incorrectly. From the MSDN Page for the CIM_Battery
class:
Important: The DMTF (Distributed Management Task Force) CIM (Common Information Model) classes are the parent classes upon which WMI classes are built.
CIM_[WHATEVER]
classes are just templates or models for what another class can implement. In the case of a battery, the proper WMI class to look at is win32_battery
class, which implements the CIM_Battery
model.