Solved

Battery Life API

Posted on 2006-07-06
11
314 Views
Last Modified: 2010-05-18
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)
0
Comment
Question by:justchat_1
  • 6
  • 2
  • 2
  • +1
11 Comments
 
LVL 5

Expert Comment

by:lunchbyte
Comment Utility
Did you check to see if your manufacture has an updated driver?
0
 
LVL 9

Author Comment

by:justchat_1
Comment Utility
The time appears in windows power management I just need a way to read it from vb
0
 
LVL 20

Expert Comment

by:hes
Comment Utility
Have a look here:
http://www.allapi.net/apilist/GetSystemPowerStatus.shtml
(Example at bottom)
0
 
LVL 5

Expert Comment

by:lunchbyte
Comment Utility
>The time appears in windows power management I just need a way to read it from vb

oh.....
0
 
LVL 9

Author Comment

by:justchat_1
Comment Utility
yes thats what I tried and it gave me an "unknown" result... I dont think it works with XP
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 41

Accepted Solution

by:
graye earned 500 total points
Comment Utility
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
 
LVL 9

Author Comment

by:justchat_1
Comment Utility
I get no output from that code...
colItems=0
0
 
LVL 9

Author Comment

by:justchat_1
Comment Utility
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
 
LVL 9

Author Comment

by:justchat_1
Comment Utility
If not thats fine too but I need a response in order to award points...
0
 
LVL 41

Expert Comment

by:graye
Comment Utility
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
 
LVL 9

Author Comment

by:justchat_1
Comment Utility
No actually you just answered my question...I was wondering how the value was stored
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now