Solved

Getting Battery Status

Posted on 2003-10-23
3
173 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses
Course of the Month3 days, 15 hours left to enroll

630 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