?
Solved

Battery Life API

Posted on 2006-07-06
11
Medium Priority
?
362 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

830 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