Solved

Battery Life API

Posted on 2006-07-06
11
321 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
ID: 17053582
Did you check to see if your manufacture has an updated driver?
0
 
LVL 9

Author Comment

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

Expert Comment

by:hes
ID: 17053919
Have a look here:
http://www.allapi.net/apilist/GetSystemPowerStatus.shtml
(Example at bottom)
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 5

Expert Comment

by:lunchbyte
ID: 17053933
>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
ID: 17054176
yes thats what I tried and it gave me an "unknown" result... I dont think it works with XP
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 17054317
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
ID: 17054522
I get no output from that code...
colItems=0
0
 
LVL 9

Author Comment

by:justchat_1
ID: 17054543
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
ID: 17068746
If not thats fine too but I need a response in order to award points...
0
 
LVL 41

Expert Comment

by:graye
ID: 17069606
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
ID: 17069925
No actually you just answered my question...I was wondering how the value was stored
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

792 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