Solved

Getting Battery Status

Posted on 2003-10-23
3
172 Views
Last Modified: 2010-05-01
I am having trouble getting the battery status on some Win 98 laptops. Both the Sysinfo control and the GetSystemPowerStatus API are unable to retrieve the status. However, the power meter in the control panel IS able to retrieve the status. Power management is turned on in the CMOS. Any ideas?
0
Comment
Question by:Neal Hartman
[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
  • 2
3 Comments
 
LVL 1

Expert Comment

by:TwistD_PissR
ID: 9608195
If you have WMI installed on the WIN98 Laptops try this:

Sub GetBatteryStatus()
Dim strComputer as String
Dim objWMIService
Dim colItems
Dim objItem
strComputer = "."
Set On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Battery",,48)
For Each objItem in colItems
    strBattery = "Availability: " & objItem.Availability
    strBattery = strBattery & "BatteryRechargeTime: " & objItem.BatteryRechargeTime
    strBattery = strBattery & "BatteryStatus: " & objItem.BatteryStatus
    strBattery = strBattery & "Caption: " & objItem.Caption
    strBattery = strBattery & "Chemistry: " & objItem.Chemistry
    strBattery = strBattery & "ConfigManagerErrorCode: " & objItem.ConfigManagerErrorCode
    strBattery = strBattery & "ConfigManagerUserConfig: " & objItem.ConfigManagerUserConfig
    strBattery = strBattery & "CreationClassName: " & objItem.CreationClassName
    strBattery = strBattery & "Description: " & objItem.Description
    strBattery = strBattery & "DesignCapacity: " & objItem.DesignCapacity
    strBattery = strBattery & "DesignVoltage: " & objItem.DesignVoltage
    strBattery = strBattery & "DeviceID: " & objItem.DeviceID
    strBattery = strBattery & "ErrorCleared: " & objItem.ErrorCleared
    strBattery = strBattery & "ErrorDescription: " & objItem.ErrorDescription
    strBattery = strBattery & "EstimatedChargeRemaining: " & objItem.EstimatedChargeRemaining
    strBattery = strBattery & "EstimatedRunTime: " & objItem.EstimatedRunTime
    strBattery = strBattery & "ExpectedBatteryLife: " & objItem.ExpectedBatteryLife
    strBattery = strBattery & "ExpectedLife: " & objItem.ExpectedLife
    strBattery = strBattery & "FullChargeCapacity: " & objItem.FullChargeCapacity
    strBattery = strBattery & "InstallDate: " & objItem.InstallDate
    strBattery = strBattery & "LastErrorCode: " & objItem.LastErrorCode
    strBattery = strBattery & "MaxRechargeTime: " & objItem.MaxRechargeTime
    strBattery = strBattery & "Name: " & objItem.Name
    strBattery = strBattery & "PNPDeviceID: " & objItem.PNPDeviceID
    strBattery = strBattery & "PowerManagementCapabilities: " & objItem.PowerManagementCapabilities
    strBattery = strBattery & "PowerManagementSupported: " & objItem.PowerManagementSupported
    strBattery = strBattery & "SmartBatteryVersion: " & objItem.SmartBatteryVersion
    strBattery = strBattery & "Status: " & objItem.Status
    strBattery = strBattery & "StatusInfo: " & objItem.StatusInfo
    strBattery = strBattery & "SystemCreationClassName: " & objItem.SystemCreationClassName
    strBattery = strBattery & "SystemName: " & objItem.SystemName
    strBattery = strBattery & "TimeOnBattery: " & objItem.TimeOnBattery
    strBattery = strBattery & "TimeToFullCharge: " & objItem.TimeToFullCharge
    MsgBox strBattery
Next
End SUb
0
 
LVL 1

Author Comment

by:Neal Hartman
ID: 9608279
Unfortunatly WMI is not installed.
0
 
LVL 1

Accepted Solution

by:
TwistD_PissR earned 500 total points
ID: 9608328
Have you tried this application yet (source is downloadable)?

http://www.karenware.com/powertools/ptprofiler.asp

It appears to use API's...
Not sure what issues you are having with the API's but its a try.

TwistD
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

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