Skip to content

Instantly share code, notes, and snippets.

@anirudh-ramesh
Created November 16, 2020 16:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anirudh-ramesh/643c668731b0d1b8f071de2e96208773 to your computer and use it in GitHub Desktop.
Save anirudh-ramesh/643c668731b0d1b8f071de2e96208773 to your computer and use it in GitHub Desktop.
Win Battery using WMI
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)
pip install wmi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment