Sign in to follow this  
Followers 0
FfmNet

Laptop AC Power / Battery Power

8 posts in this topic

i am newbie ... is it possible to get information from windows xp system, what kind of power the laptop use ? AC or Battery ?

i want to create a patchupdate script wich i checking before the power information (AC or Battery)

maby i get a infoamtion if this is possible or not.

thank you ...

:)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

link

and example from the forum:

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 Zedna

Share this post


Link to post
Share on other sites

compinfo.au3 should be able to help you. I have not tested these suggestions, but the _ComputerGetBattery and _ComputerGetSystem functions return information that should be coming in very handy in your situation.

http://www.autoitscript.com/forum/index.ph...hl=compinfo.au3


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Zedna, your link appears to be broken... :)


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Zedna, your link appears to be broken... :)

Then here is code from there:

$SYSTEM_POWER_STATUS = DLLStructCreate("byte;byte;byte;byte;int;int")

$test = DLLCall("kernel32.dll","int","GetSystemPowerStatus", _
        "ptr",DllStructGetPtr($SYSTEM_POWER_STATUS))

If $test[0] Then
    MsgBox(4096,"",DLLStructGetData($SYSTEM_POWER_STATUS,1))
    MsgBox(4096,"",DLLStructGetData($SYSTEM_POWER_STATUS,3))
EndIf

#cs
SYSTEM_POWER_STATUS

Contains information about the power status of the system.

typedef struct _SYSTEM_POWER_STATUS {
  BYTE ACLineStatus;
  BYTE BatteryFlag;
  BYTE BatteryLifePercent;
  BYTE Reserved1;
  DWORD BatteryLifeTime;
  DWORD BatteryFullLifeTime;
} SYSTEM_POWER_STATUS,
 *LPSYSTEM_POWER_STATUS;

Members

ACLineStatus
    The AC power status. This member can be one of the following values.
    Value   Meaning
    0   Offline
    1   Online
    255  Unknown status
BatteryFlag
    The battery charge status. This member can contain one or more of the following flags.
    Value   Meaning
    1   High-the battery capacity is at more than 66 percent
    2   Low-the battery capacity is at less than 33 percent
    4   Critical-the battery capacity is at less than five percent
    8   Charging
    128  No system battery
    255  Unknown status-unable to read the battery flag information

    The value is zero if the battery is not being charged and the battery capacity is between low and high.
BatteryLifePercent
    The percentage of full battery charge remaining. This member can be a value in the range 0 to 100, or 255 if status is unknown.
Reserved1
    Reserved; must be zero.
BatteryLifeTime
    The number of seconds of battery life remaining, or -1 if remaining seconds are unknown.
BatteryFullLifeTime
    The number of seconds of battery life when at full charge, or -1 if full battery lifetime is unknown.
#ce

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Zedna your first script generates an empty file (XP SP2, small form factor desktop)

Battery Information

**********************

I came up with this script but it also returns nothing.

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

$strComputer = "."
;$strComputer = "localhost"

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")
If @ERROR Then 
    MsgBox(0,"","Error creating object")
    Exit
EndIf

$colItems = $objWMIService.ExecQuery("Select * From BatteryStatus", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

For $objItem in $colItems
    ConsoleWrite("Battery: " & $objItem.InstanceName)
    ConsoleWrite("On AC Power: " & $objItem.PowerOnline)
    ConsoleWrite("Battery is Discharging: " & $objItem.Discharging)
    ConsoleWrite("Battery is Charging: " & $objItem.Charging)
    ConsoleWrite("Remaining capacity: " & $objItem.RemainingCapacity)
Next

From here:

http://www.microsoft.com/technet/scriptcen...07/hey0409.mspx

Edited by weaponx

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Zedna your first script generates an empty file (XP SP2, small form factor desktop)

These are old scripts from forum. It nay be incompatible with latest AutoIt.

I put it here just for giving right way no as exact solution.

EDIT: I recommend to look at CompInfo UDF too.

Edited by Zedna

Share this post


Link to post
Share on other sites

compinfo.au3 is the soloution for me.

thanks a lot guys ...

:)

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