Solved

Getting Battery Status

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

820 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