Created
November 16, 2020 16:55
-
-
Save anirudh-ramesh/643c668731b0d1b8f071de2e96208773 to your computer and use it in GitHub Desktop.
Win Battery using WMI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wmi | |
c = wmi.WMI() | |
t = wmi.WMI(moniker = "//./root/wmi") | |
batts1 = c.CIM_Battery(Caption = 'Portable Battery') | |
for i, b in enumerate(batts1): | |
print 'Battery %d Design Capacity: %d mWh' % (i, b.DesignCapacity or 0) | |
batts = t.ExecQuery('Select * from BatteryFullChargedCapacity') | |
for i, b in enumerate(batts): | |
print ('Battery %d Fully Charged Capacity: %d mWh' % | |
(i, b.FullChargedCapacity)) | |
batts = t.ExecQuery('Select * from BatteryStatus where Voltage > 0') | |
for i, b in enumerate(batts): | |
print '\nBattery %d ***************' % i | |
print 'Tag: ' + str(b.Tag) | |
print 'Name: ' + b.InstanceName | |
print 'PowerOnline: ' + str(b.PowerOnline) | |
print 'Discharging: ' + str(b.Discharging) | |
print 'Charging: ' + str(b.Charging) | |
print 'Voltage: ' + str(b.Voltage) | |
print 'DischargeRate: ' + str(b.DischargeRate) | |
print 'ChargeRate: ' + str(b.ChargeRate) | |
print 'RemainingCapacity: ' + str(b.RemainingCapacity) | |
print 'Active: ' + str(b.Active) | |
print 'Critical: ' + str(b.Critical) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install wmi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment