C
C#13mo ago
Tostisto

❔ Laptop Battery Info

I would like to create a simple app that monitors information about the battery, such as its overall health, capacity, voltage, and other relevant details. Currently, I have create a basic console app in .NET Core that retrieves some information about the battery. Here's the existing code:
using System;
using System.Management;

class Program
{
static void Main()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Battery");

foreach (ManagementObject queryObj in searcher.Get())
{
PropertyDataCollection properties = queryObj.Properties;

foreach (PropertyData property in properties)
{
Console.WriteLine($"{property.Name}: {property.Value}");
}
}
}
}
using System;
using System.Management;

class Program
{
static void Main()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Battery");

foreach (ManagementObject queryObj in searcher.Get())
{
PropertyDataCollection properties = queryObj.Properties;

foreach (PropertyData property in properties)
{
Console.WriteLine($"{property.Name}: {property.Value}");
}
}
}
}
However, this code does not provide all the desired information about the battery. I need to retrieve additional details like the current battery capacity and designed battery capacity. How can I modify the code to obtain these missing or additional battery information? Here's the sample output from the current code:
Availability: 2
BatteryRechargeTime:
BatteryStatus: 2
Caption: Internal Battery
Chemistry: 2
ConfigManagerErrorCode:
ConfigManagerUserConfig:
CreationClassName: Win32_Battery
Description: Internal Battery
DesignCapacity:
DesignVoltage: 12822
DeviceID: 5650CelxpertL19C3PF3
ErrorCleared:
ErrorDescription:
EstimatedChargeRemaining: 88
EstimatedRunTime: 71582788
ExpectedBatteryLife:
ExpectedLife:
FullChargeCapacity:
InstallDate:
LastErrorCode:
MaxRechargeTime:
Name: L19C3PF3
PNPDeviceID:
PowerManagementCapabilities: System.UInt16[]
PowerManagementSupported: False
SmartBatteryVersion:
Status: OK
StatusInfo:
SystemCreationClassName: Win32_ComputerSystem
SystemName: LAPTOP
TimeOnBattery:
TimeToFullCharge:
Availability: 2
BatteryRechargeTime:
BatteryStatus: 2
Caption: Internal Battery
Chemistry: 2
ConfigManagerErrorCode:
ConfigManagerUserConfig:
CreationClassName: Win32_Battery
Description: Internal Battery
DesignCapacity:
DesignVoltage: 12822
DeviceID: 5650CelxpertL19C3PF3
ErrorCleared:
ErrorDescription:
EstimatedChargeRemaining: 88
EstimatedRunTime: 71582788
ExpectedBatteryLife:
ExpectedLife:
FullChargeCapacity:
InstallDate:
LastErrorCode:
MaxRechargeTime:
Name: L19C3PF3
PNPDeviceID:
PowerManagementCapabilities: System.UInt16[]
PowerManagementSupported: False
SmartBatteryVersion:
Status: OK
StatusInfo:
SystemCreationClassName: Win32_ComputerSystem
SystemName: LAPTOP
TimeOnBattery:
TimeToFullCharge:
1 Reply
Accord
Accord13mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.