Solved

Getting Battery Status

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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.
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 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…

738 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