Sign in to follow this  
Followers 0
Selmak

Detect Battery Operation

6 posts in this topic

Any idea how I could detect programmatically that a laptop is running on battery power?

(Specifically Acer Aspire / Turion ML30 processor, but a generic solution would be preferred.)

Share this post


Link to post
Share on other sites



Best way will be through WMI classes: Win32_Battery

Microsoft MSDN - Win32_Battery

Here is example of using WMI:

Dim $info

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$objDisks = $objWMIservice.ExecQuery ("Select * from Win32_DiskDrive")

For $object In $objDisks
    $info &= 'Availability: ' & $object.Availability & @CRLF
    $info &= 'BytesPerSector: ' & $object.BytesPerSector & @CRLF
    $info &= 'Caption: ' & $object.Caption & @CRLF
    $info &= 'Description: ' & $object.Description & @CRLF
    $info &= 'DeviceID: ' & $object.DeviceID & @CRLF
    $info &= 'Index: ' & $object.Index & @CRLF
    $info &= 'InterfaceType: ' & $object.InterfaceType & @CRLF
    $info &= 'Manufacturer: ' & $object.Manufacturer & @CRLF
    $info &= 'MediaType: ' & $object.MediaType & @CRLF
    $info &= 'Model: ' & $object.Model & @CRLF
    $info &= 'Name: ' & $object.Name & @CRLF
    $info &= 'NumberOfMediaSupported: ' & $object.NumberOfMediaSupported & @CRLF
    $info &= 'Partitions: ' & $object.Partitions & @CRLF
    $info &= 'PowerManagementSupported: ' & $object.PowerManagementSupported & @CRLF
    $info &= 'Size: ' & $object.Size & @CRLF
    $info &= 'Status: ' & $object.Status & @CRLF
    $info &= 'StatusInfo: ' & $object.StatusInfo & @CRLF
    $info &= 'SystemName: ' & $object.SystemName & @CRLF

    $info &= @CRLF & @CRLF
Next

FileWrite('disk_info.txt', "Disk Information" & @CRLF & "********************" & @CRLF & @CRLF & $info)

Share this post


Link to post
Share on other sites

Best way will be through WMI classes: Win32_Battery

Thanks I'll give that a try.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I made this just now. This is cool, there is a lot of info, I can wait to use this for some other hardware, Thanks man

CODE
Dim $info

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

$objBatt = $objWMIservice.ExecQuery ("Select * from Win32_Battery")

For $object In $objBatt

$info &= 'Availability: ' & $object.Availability & @CRLF

$info &= 'BatteryRechargeTime: ' & $object.BatteryRechargeTime & @CRLF

$info &= 'BatteryStatus: ' & $object.BatteryStatus & @CRLF

$info &= 'Caption: ' & $object.Caption & @CRLF

$info &= 'Chemistry: ' & $object.Chemistry & @CRLF

$info &= 'ConfigManagerErrorCode: ' & $object.ConfigManagerErrorCode & @CRLF

$info &= 'ConfigManagerUserConfig: ' & $object.ConfigManagerUserConfig & @CRLF

$info &= 'CreationClassName: ' & $object.CreationClassName & @CRLF

$info &= 'Description: ' & $object.Description & @CRLF

$info &= 'DesignCapacity: ' & $object.DesignCapacity & @CRLF

$info &= 'DesignVoltage: ' & $object.DesignVoltage & @CRLF

$info &= 'DeviceID: ' & $object.DeviceID & @CRLF

$info &= 'ErrorCleared: ' & $object.ErrorCleared & @CRLF

$info &= 'ErrorDescription: ' & $object.ErrorDescription & @CRLF

$info &= 'EstimatedChargeRemaining: ' & $object.EstimatedChargeRemaining & @CRLF

$info &= 'EstimatedRunTime: ' & $object.EstimatedRunTime & @CRLF

$info &= 'ExpectedBatteryLife: ' & $object.ExpectedBatteryLife & @CRLF

$info &= 'ExpectedLife: ' & $object.ExpectedLife & @CRLF

$info &= 'FullChargeCapacity: ' & $object.FullChargeCapacity & @CRLF

$info &= 'InstallDate: ' & $object.InstallDate & @CRLF

$info &= 'LastErrorCode: ' & $object.LastErrorCode & @CRLF

$info &= 'MaxRechargeTime: ' & $object.MaxRechargeTime & @CRLF

$info &= 'Name: ' & $object.Name & @CRLF

$info &= 'PNPDeviceID: ' & $object.PNPDeviceID & @CRLF

$info &= 'PowerManagementCapabilities[]: ' & $object.PowerManagementCapabilities & @CRLF

$info &= 'PowerManagementSupported: ' & $object.PowerManagementSupported & @CRLF

$info &= 'SmartBatteryVersion: ' & $object.SmartBatteryVersion & @CRLF

$info &= 'PowerManagementSupported: ' & $object.PowerManagementSupported & @CRLF

$info &= 'Status: ' & $object.Status & @CRLF

$info &= 'StatusInfo: ' & $object.StatusInfo & @CRLF

$info &= 'SystemCreationClassName: ' & $object.SystemCreationClassName & @CRLF

$info &= 'SystemName: ' & $object.SystemName & @CRLF

$info &= 'TimeOnBattery: ' & $object.TimeOnBattery & @CRLF

$info &= 'TimeToFullCharge: ' & $object.TimeToFullCharge & @CRLF

Next

FileWrite('battery_info.txt', "Battery Information" & @CRLF & "**********************" & @CRLF & @CRLF & $info)

Edited by zerocool60544

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Share this post


Link to post
Share on other sites

one thing I am having a problem with is setting data to an object that has write capabilities, I tried

$obj.VariableSpeed = "True"

$obj.desiredSpeed = 100


[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0