Selmak Posted April 23, 2006 Posted April 23, 2006 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.)
Zedna Posted April 23, 2006 Posted April 23, 2006 Best way will be through WMI classes: Win32_BatteryMicrosoft MSDN - Win32_BatteryHere 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) Resources UDF ResourcesEx UDF AutoIt Forum Search
Selmak Posted April 25, 2006 Author Posted April 25, 2006 Best way will be through WMI classes: Win32_BatteryThanks I'll give that a try.
CyberSlug Posted April 25, 2006 Posted April 25, 2006 This should also help:http://www.autoitscript.com/forum/index.ph...1000&hl=batteryP.S. All this code requires the beta version of AutoIt http://www.autoitscript.com/autoit3/files/beta/autoit/ Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
ConsultingJoe Posted April 25, 2006 Posted April 25, 2006 (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 CODEDim $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 April 25, 2006 by zerocool60544 Check out ConsultingJoe.com
ConsultingJoe Posted April 25, 2006 Posted April 25, 2006 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 Check out ConsultingJoe.com
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now