Battery Life API

I am trying to find the number of minutes remaining for my laptop battery.  I have tried the system powerstate's battery lifetime but it returns -1 (Unknown)
Who is Participating?
grayeConnect With a Mentor Commented:
I'd recommend that you use Windows Management Instrumentation (WMI).

Here is an example that demonstrate the concepts

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_Battery",,48)
For Each objItem in colItems
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_Battery instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "BatteryRechargeTime: " & objItem.BatteryRechargeTime
    Wscript.Echo "BatteryStatus: " & objItem.BatteryStatus
    Wscript.Echo "DesignCapacity: " & objItem.DesignCapacity
    Wscript.Echo "DesignVoltage: " & objItem.DesignVoltage
    Wscript.Echo "EstimatedChargeRemaining: " & objItem.EstimatedChargeRemaining
    Wscript.Echo "EstimatedRunTime: " & objItem.EstimatedRunTime
    Wscript.Echo "ExpectedBatteryLife: " & objItem.ExpectedBatteryLife
    Wscript.Echo "ExpectedLife: " & objItem.ExpectedLife
    Wscript.Echo "FullChargeCapacity: " & objItem.FullChargeCapacity
    Wscript.Echo "MaxRechargeTime: " & objItem.MaxRechargeTime
    Wscript.Echo "Status: " & objItem.Status
    Wscript.Echo "TimeOnBattery: " & objItem.TimeOnBattery
    Wscript.Echo "TimeToFullCharge: " & objItem.TimeToFullCharge
Did you check to see if your manufacture has an updated driver?
justchat_1Author Commented:
The time appears in windows power management I just need a way to read it from vb
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Have a look here:
(Example at bottom)
>The time appears in windows power management I just need a way to read it from vb

justchat_1Author Commented:
yes thats what I tried and it gave me an "unknown" result... I dont think it works with XP
justchat_1Author Commented:
I get no output from that code...
justchat_1Author Commented:
correction.. most of those items dont appear but the one I needed does-thanks...

Can you tell me what format voltage is stored in?  It would be nice to be able to read that also
justchat_1Author Commented:
If not thats fine too but I need a response in order to award points...
I'm not sure I understand the question....   The documentation for the Win32_Battery class ( has only one property that deal with voltage.   The unit of measure is milivolts and the value is stored in an Unsigned 64-bit Integer (Uint64).  Since VB can't deal with UInt64 values, most folks read the value as a string and then use CDbl() to convert it to a double .

Are you perhaps talking about the Temperature and Voltage "probes" that are available on most motherboards?  If so, then I know of no motherboard manufacturer that has created a WMI provider for Temperature and Voltage.
justchat_1Author Commented:
No actually you just answered my question...I was wondering how the value was stored
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.