Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Checking Laptop battery info

by stonecolddevin (Vicar)
on Jul 09, 2006 at 09:17 UTC ( #559984=note: print w/ replies, xml ) Need Help??


in reply to Checking Laptop battery info

what would it take for something like this to be done for windows/mac?

meh.


Comment on Re: Checking Laptop battery info
Re^2: Checking Laptop battery info
by planetscape (Canon) on Jul 09, 2006 at 22:14 UTC

      Micro$oft does have VBS code, which can serve as a starting point. After all, translating from VBS to Perl should be easy &foolish_grin;

      Microsoft scripting center

      emc

      e(π√−1) = −1
Re^2: Checking Laptop battery info
by !1 (Hermit) on Jul 10, 2006 at 02:46 UTC

    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. =/

      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"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://559984]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2014-12-18 06:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (43 votes), past polls