http://www.perlmonks.org?node_id=560059


in reply to Re: Checking Laptop battery info
in thread Checking Laptop battery info

For win you could do something like this:

#!/usr/bin/perl -l use Win32::OLE('in'); my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\.\\root\\cimv2 +") or die "WMI connection failed.\n"; $colItems = $objWMIService->ExecQuery("Select * from Win32_Battery","W +QL",0x30); print "$_->{DeviceID} ($_->{Description}): $_->{EstimatedChargeRemaini +ng}%" for in $colItems;

Of course, I get percentages greater than 100% when I'm plugged in so it isn't completely ideal. =/

Replies are listed 'Best First'.
Re^3: Checking Laptop battery info
by stonecolddevin (Parson) on Jul 10, 2006 at 20:59 UTC

    well it's most certainly a start. if nothing else i can be like, "hey dad, check this out" :-)

    might even be able to play around with it and see what the problem is with the percentages...

    meh.
      For Windows scripting checkout Scriptomatic 2.0 from the microsoft scripting guys...
      use strict; use Win32::OLE('in'); use constant wbemFlagReturnImmediately => 0x10; use constant wbemFlagForwardOnly => 0x20; my $computer = "localhost"; my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\roo +t\\CIMV2") or die "WMI connection failed.\n"; my $colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_Battery" +, "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly); foreach my $objItem (in $colItems) { print "Availability: $objItem->{Availability}\n"; print "BatteryRechargeTime: $objItem->{BatteryRechargeTime}\n"; print "BatteryStatus: $objItem->{BatteryStatus}\n"; print "Caption: $objItem->{Caption}\n"; print "Chemistry: $objItem->{Chemistry}\n"; print "ConfigManagerErrorCode: $objItem->{ConfigManagerErrorCode}\n +"; print "ConfigManagerUserConfig: $objItem->{ConfigManagerUserConfig} +\n"; print "CreationClassName: $objItem->{CreationClassName}\n"; print "Description: $objItem->{Description}\n"; print "DesignCapacity: $objItem->{DesignCapacity}\n"; print "DesignVoltage: $objItem->{DesignVoltage}\n"; print "DeviceID: $objItem->{DeviceID}\n"; print "ErrorCleared: $objItem->{ErrorCleared}\n"; print "ErrorDescription: $objItem->{ErrorDescription}\n"; print "EstimatedChargeRemaining: $objItem->{EstimatedChargeRemainin +g}\n"; print "EstimatedRunTime: $objItem->{EstimatedRunTime}\n"; print "ExpectedBatteryLife: $objItem->{ExpectedBatteryLife}\n"; print "ExpectedLife: $objItem->{ExpectedLife}\n"; print "FullChargeCapacity: $objItem->{FullChargeCapacity}\n"; print "InstallDate: $objItem->{InstallDate}\n"; print "LastErrorCode: $objItem->{LastErrorCode}\n"; print "MaxRechargeTime: $objItem->{MaxRechargeTime}\n"; print "Name: $objItem->{Name}\n"; print "PNPDeviceID: $objItem->{PNPDeviceID}\n"; print "PowerManagementCapabilities: " . join(",", (in $objItem->{Po +werManagementCapabilities})) . "\n"; print "PowerManagementSupported: $objItem->{PowerManagementSupporte +d}\n"; print "SmartBatteryVersion: $objItem->{SmartBatteryVersion}\n"; print "Status: $objItem->{Status}\n"; print "StatusInfo: $objItem->{StatusInfo}\n"; print "SystemCreationClassName: $objItem->{SystemCreationClassName} +\n"; print "SystemName: $objItem->{SystemName}\n"; print "TimeOnBattery: $objItem->{TimeOnBattery}\n"; print "TimeToFullCharge: $objItem->{TimeToFullCharge}\n"; print "\n"; } sub WMIDateStringToDate(strDate){ return "blah"; }