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)
LVL 9
justchat_1Asked:
Who is Participating?
 
grayeConnect With a Mentor Commented:
I'd recommend that you use Windows Management Instrumentation (WMI).  

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_battery.asp

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
Next
0
 
lunchbyteCommented:
Did you check to see if your manufacture has an updated driver?
0
 
justchat_1Author Commented:
The time appears in windows power management I just need a way to read it from vb
0
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.

 
hesCommented:
Have a look here:
http://www.allapi.net/apilist/GetSystemPowerStatus.shtml
(Example at bottom)
0
 
lunchbyteCommented:
>The time appears in windows power management I just need a way to read it from vb

oh.....
0
 
justchat_1Author Commented:
yes thats what I tried and it gave me an "unknown" result... I dont think it works with XP
0
 
justchat_1Author Commented:
I get no output from that code...
colItems=0
0
 
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
0
 
justchat_1Author Commented:
If not thats fine too but I need a response in order to award points...
0
 
grayeCommented:
I'm not sure I understand the question....   The documentation for the Win32_Battery class (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_battery.asp) 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.
0
 
justchat_1Author Commented:
No actually you just answered my question...I was wondering how the value was stored
0
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.