Solved

Battery Life API

Posted on 2006-07-06
11
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Zip Folders Using Chilkat Routines 1 86
VB6 - Scroll Mouse wheel on Picturebox 13 119
backup program with robocopy 6 91
VBA Replace Function - What am I missing? 3 51
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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