Solved

Getting Battery Status

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now