argumentum

_WinAPI_GetSystemPowerStatus for 2 UPSs

10 posts in this topic

So I've got 2 UPSs connected to 3 PCs and with the USB connectors to 1 PC.
The load is not even and they discharge at different rates.
_WinAPI_GetSystemPowerStatus() gives me an average reading ( 1 UPS can be at 90% and the other at 10% ) but is lighter than WMI.  
WMI Win32_Battery gives me independent readings but is heavier to run.

My question is: is there a DLL way ( as in the WinAPI call ) to get independent reading as WMI does ?

( This WMI code below is not needed to answer my question, but here it is anyway ) 

#include "Array.au3"

Opt("MustDeclareVars",1)
Opt("TrayIconDebug",1)
Opt("TrayAutoPause",0)
Global $_nice_COMerrorArray, $_nice_COMerrorObj
_nice_COMerrorHandler(1) ; COM error handler.

ToolTip("mouse over the trayicon for debug info.", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Battery",1,4)

Local $a = _WMI_Win32_Battery()
If @error Then
    Switch @error
        Case 1
            MsgBox(262144, "WMI ScriptOMatic error", "No WMI Objects Found for class: ""Win32_Battery""" )
        Case 2
            MsgBox(262144, "WMI ScriptOMatic error", "ObjGet failed")
        Case 3
            MsgBox(262144, "WMI ScriptOMatic error", "ObjCreate failed")
        Case 4
            MsgBox(262144, "WMI ScriptOMatic error", "ConnectServer failed")
        Case Else
            MsgBox(262144, "WMI ScriptOMatic error", "unknown error")
    EndSwitch
Else
    Switch @extended
        Case 0
            ToolTip("Done.", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Battery",1,4)
        Case 1
            ToolTip("Nothing, you've got nothing."&@CR&@CR&"Adjust the query", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Battery",2,4)
        Case 2
            ToolTip("More than you can chew."&@CR&@CR&"Adjust the ""$iLimit"" or the query", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Battery",2,4)
    EndSwitch
    If $_nice_COMerrorArray[0][0] Then _nice_COMerrorHandler(2)
    _ArrayDisplay( $a ,"ScriptOMatic - ""Win32_Battery""")
EndIf


Func _WMI_Win32_Battery( $iLimit = 1020 , $sComputer = "." , $sUser = "" , $sPassword = "" )

    ; Generated by AutoIt ScriptOMatic

    ; Description: The Win32_Battery class represents a battery connected to the computer system.
    ;         This class applies to both batteries in Laptop Systems and other internal/external batteries.


    ; Class Methods:
    ;
    ; SetPowerState
    ; Reset


    Local $wbemFlagReturnImmediately = 0x10
    Local $wbemFlagForwardOnly = 0x20
    Local $colItems = ""
    Local $sReturn=""
    Local $iExt = 0
    If 1 > Int( $iLimit ) Then $iLimit = 1
    Local $aReturn[1000][ Int( $iLimit ) + 1]
    $aReturn[0][0] = 0
    $aReturn[0][1] = 0
    Local $aErr[1][2] = [[0, 0]]

    If $sComputer & $sUser & $sPassword = "." Then
        ToolTip("...ObjGet", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Battery",1,4)
        Local $oWMIService = ObjGet("winmgmts:\\" & $sComputer & "\root\CIMV2")
        If Not IsObj($oWMIService) Then Return SetError(2, 99, $aErr)
    Else
        ToolTip("...ObjCreate", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Battery",1,4)
        Local $wmiLocator = ObjCreate("WbemScripting.SWbemLocator")
        If Not IsObj($wmiLocator) Then Return SetError(3, 99, $aErr)
        ToolTip("...ConnectServer", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Battery",1,4)
        Local $oWMIService = $wmiLocator.ConnectServer($sComputer, "\root\CIMV2", $sUser, $sPassword)
        If Not IsObj($oWMIService) Then Return SetError(4, 99, $aErr)
    EndIf

    ToolTip("...ExecQuery", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Battery",1,4)
    Local $colItems = $oWMIService.ExecQuery("SELECT * FROM Win32_Battery", _
                         "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    ToolTip("...ExecQuery executed."& @CR &"...waiting for data.", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Battery",1,4)
    If IsObj($colItems) Then

        ; Class Properties: Names:
        ;

        $aReturn[  1 ][ 0 ] = "Availability"
        $aReturn[  2 ][ 0 ] = "BatteryRechargeTime"
        $aReturn[  3 ][ 0 ] = "BatteryStatus"
        $aReturn[  4 ][ 0 ] = "Caption"
        $aReturn[  5 ][ 0 ] = "Chemistry"
        $aReturn[  6 ][ 0 ] = "ConfigManagerErrorCode"
        $aReturn[  7 ][ 0 ] = "ConfigManagerUserConfig"
        $aReturn[  8 ][ 0 ] = "CreationClassName"
        $aReturn[  9 ][ 0 ] = "Description"
        $aReturn[ 10 ][ 0 ] = "DesignCapacity"
        $aReturn[ 11 ][ 0 ] = "DesignVoltage"
        $aReturn[ 12 ][ 0 ] = "DeviceID"
        $aReturn[ 13 ][ 0 ] = "ErrorCleared"
        $aReturn[ 14 ][ 0 ] = "ErrorDescription"
        $aReturn[ 15 ][ 0 ] = "EstimatedChargeRemaining"
        $aReturn[ 16 ][ 0 ] = "EstimatedRunTime"
        $aReturn[ 17 ][ 0 ] = "ExpectedBatteryLife"
        $aReturn[ 18 ][ 0 ] = "ExpectedLife"
        $aReturn[ 19 ][ 0 ] = "FullChargeCapacity"
        $aReturn[ 20 ][ 0 ] = "InstallDate"
        $aReturn[ 21 ][ 0 ] = "LastErrorCode"
        $aReturn[ 22 ][ 0 ] = "MaxRechargeTime"
        $aReturn[ 23 ][ 0 ] = "Name"
        $aReturn[ 24 ][ 0 ] = "PNPDeviceID"
        $aReturn[ 25 ][ 0 ] = "PowerManagementCapabilities"
        $aReturn[ 26 ][ 0 ] = "PowerManagementSupported"
        $aReturn[ 27 ][ 0 ] = "SmartBatteryVersion"
        $aReturn[ 28 ][ 0 ] = "Status"
        $aReturn[ 29 ][ 0 ] = "StatusInfo"
        $aReturn[ 30 ][ 0 ] = "SystemCreationClassName"
        $aReturn[ 31 ][ 0 ] = "SystemName"
        $aReturn[ 32 ][ 0 ] = "TimeOnBattery"
        $aReturn[ 33 ][ 0 ] = "TimeToFullCharge"
        $aReturn[0][0] = 33
        For $objItem In $colItems
            $aReturn[0][1] = $aReturn[0][1] + 1
            If Not Mod( $aReturn[0][1] , 100 ) Then ToolTip("...adding "& $aReturn[0][1] &" of "&$iLimit &" ??", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Battery",1,4)
            If $aReturn[0][1] > $iLimit Then
                $iExt = 2
                ExitLoop
            EndIf

            ; Class Properties: Values:
            ;

            $aReturn[  1 ][ $aReturn[0][1] ] = Win32_Battery_PropertyValues_Availability( $objItem.Availability )
            $aReturn[  2 ][ $aReturn[0][1] ] = $objItem.BatteryRechargeTime
            $aReturn[  3 ][ $aReturn[0][1] ] = Win32_Battery_PropertyValues_BatteryStatus( $objItem.BatteryStatus )
            $aReturn[  4 ][ $aReturn[0][1] ] = $objItem.Caption
            $aReturn[  5 ][ $aReturn[0][1] ] = Win32_Battery_PropertyValues_Chemistry( $objItem.Chemistry )
            $aReturn[  6 ][ $aReturn[0][1] ] = Win32_Battery_PropertyValues_ConfigManagerErrorCode( $objItem.ConfigManagerErrorCode )
            $aReturn[  7 ][ $aReturn[0][1] ] = $objItem.ConfigManagerUserConfig
            $aReturn[  8 ][ $aReturn[0][1] ] = $objItem.CreationClassName
            $aReturn[  9 ][ $aReturn[0][1] ] = $objItem.Description
            $aReturn[ 10 ][ $aReturn[0][1] ] = $objItem.DesignCapacity
            $aReturn[ 11 ][ $aReturn[0][1] ] = $objItem.DesignVoltage
            $aReturn[ 12 ][ $aReturn[0][1] ] = $objItem.DeviceID
            $aReturn[ 13 ][ $aReturn[0][1] ] = $objItem.ErrorCleared
            $aReturn[ 14 ][ $aReturn[0][1] ] = $objItem.ErrorDescription
            $aReturn[ 15 ][ $aReturn[0][1] ] = $objItem.EstimatedChargeRemaining
            $aReturn[ 16 ][ $aReturn[0][1] ] = $objItem.EstimatedRunTime
            $aReturn[ 17 ][ $aReturn[0][1] ] = $objItem.ExpectedBatteryLife
            $aReturn[ 18 ][ $aReturn[0][1] ] = $objItem.ExpectedLife
            $aReturn[ 19 ][ $aReturn[0][1] ] = $objItem.FullChargeCapacity
            $aReturn[ 20 ][ $aReturn[0][1] ] = WMIDateStringToDate( $objItem.InstallDate )
            $aReturn[ 21 ][ $aReturn[0][1] ] = $objItem.LastErrorCode
            $aReturn[ 22 ][ $aReturn[0][1] ] = $objItem.MaxRechargeTime
            $aReturn[ 23 ][ $aReturn[0][1] ] = $objItem.Name
            $aReturn[ 24 ][ $aReturn[0][1] ] = $objItem.PNPDeviceID
            $aReturn[ 25 ][ $aReturn[0][1] ] = Array_Join( $objItem.PowerManagementCapabilities )
            $aReturn[ 26 ][ $aReturn[0][1] ] = $objItem.PowerManagementSupported
            $aReturn[ 27 ][ $aReturn[0][1] ] = $objItem.SmartBatteryVersion
            $aReturn[ 28 ][ $aReturn[0][1] ] = $objItem.Status
            $aReturn[ 29 ][ $aReturn[0][1] ] = Win32_Battery_PropertyValues_StatusInfo( $objItem.StatusInfo )
            $aReturn[ 30 ][ $aReturn[0][1] ] = $objItem.SystemCreationClassName
            $aReturn[ 31 ][ $aReturn[0][1] ] = $objItem.SystemName
            $aReturn[ 32 ][ $aReturn[0][1] ] = $objItem.TimeOnBattery
            $aReturn[ 33 ][ $aReturn[0][1] ] = $objItem.TimeToFullCharge
        Next
        If $aReturn[0][1] = 0  Then $iExt = 1
        ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1] + 1]
        Return SetError( 0 , $iExt , $aReturn )
    Else
        Return SetError(1 ,99 ,$aErr)
    EndIf
EndFunc

Func WMIDateStringToDate($dtmDate)
    Return (StringMid($dtmDate, 5, 2) & "/" & _
        StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
        & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

Func Array_Join($aArray, $sSeparator = " , ")
    Local $n, $sOut = ""
    If IsObj($aArray) Then
        For $value In $aArray
            $sOut &= $value & $sSeparator
        Next
        Return StringTrimRight($sOut, StringLen($sSeparator))
    Else
        For $n = 0 To UBound($aArray) - 1
            $sOut &= $aArray[$n] & $sSeparator
        Next
        Return StringTrimRight($sOut, StringLen($sSeparator))
    EndIf
EndFunc   ;==>Array_Join

#Region    # ValueToDescription Functions #


Func Win32_Battery_PropertyValues_Availability( $value )
    Switch $value
        Case "1"
            Return "1 = Other"
        Case "2"
            Return "2 = Unknown"
        Case "3"
            Return "3 = Running/Full Power"
        Case "4"
            Return "4 = Warning"
        Case "5"
            Return "5 = In Test"
        Case "6"
            Return "6 = Not Applicable"
        Case "7"
            Return "7 = Power Off"
        Case "8"
            Return "8 = Off Line"
        Case "9"
            Return "9 = Off Duty"
        Case "10"
            Return "10 = Degraded"
        Case "11"
            Return "11 = Not Installed"
        Case "12"
            Return "12 = Install Error"
        Case "13"
            Return "13 = Power Save - Unknown"
        Case "14"
            Return "14 = Power Save - Low Power Mode"
        Case "15"
            Return "15 = Power Save - Standby"
        Case "16"
            Return "16 = Power Cycle"
        Case "17"
            Return "17 = Power Save - Warning"
        Case "18"
            Return "18 = Paused"
        Case "19"
            Return "19 = Not Ready"
        Case "20"
            Return "20 = Not Configured"
        Case "21"
            Return "21 = Quiesced"
        Case Else
            Return $value&" = ???"
    EndSwitch
EndFunc

Func Win32_Battery_PropertyValues_BatteryStatus( $value )
    Switch $value
        Case "1"
            Return "1 = Other"
        Case "2"
            Return "2 = Unknown"
        Case "3"
            Return "3 = Fully Charged"
        Case "4"
            Return "4 = Low"
        Case "5"
            Return "5 = Critical"
        Case "6"
            Return "6 = Charging"
        Case "7"
            Return "7 = Charging and High"
        Case "8"
            Return "8 = Charging and Low"
        Case "9"
            Return "9 = Charging and Critical"
        Case "10"
            Return "10 = Undefined"
        Case "11"
            Return "11 = Partially Charged"
        Case Else
            Return $value&" = ???"
    EndSwitch
EndFunc

Func Win32_Battery_PropertyValues_Chemistry( $value )
    Switch $value
        Case "1"
            Return "1 = Other"
        Case "2"
            Return "2 = Unknown"
        Case "3"
            Return "3 = Lead Acid"
        Case "4"
            Return "4 = Nickel Cadmium"
        Case "5"
            Return "5 = Nickel Metal Hydride"
        Case "6"
            Return "6 = Lithium-ion"
        Case "7"
            Return "7 = Zinc air"
        Case "8"
            Return "8 = Lithium Polymer"
        Case Else
            Return $value&" = ???"
    EndSwitch
EndFunc

Func Win32_Battery_PropertyValues_ConfigManagerErrorCode( $value )
    Switch $value
        Case "0"
            Return "0 = This device is working properly."
        Case "1"
            Return "1 = This device is not configured correctly."
        Case "2"
            Return "2 = Windows cannot load the driver for this device."
        Case "3"
            Return "3 = The driver for this device might be corrupted, or your system may be running low on memory or other resources."
        Case "4"
            Return "4 = This device is not working properly. One of its drivers or your registry might be corrupted."
        Case "5"
            Return "5 = The driver for this device needs a resource that Windows cannot manage."
        Case "6"
            Return "6 = The boot configuration for this device conflicts with other devices."
        Case "7"
            Return "7 = Cannot filter."
        Case "8"
            Return "8 = The driver loader for the device is missing."
        Case "9"
            Return "9 = This device is not working properly because the controlling firmware is reporting the resources for the device incorrectly."
        Case "10"
            Return "10 = This device cannot start."
        Case "11"
            Return "11 = This device failed."
        Case "12"
            Return "12 = This device cannot find enough free resources that it can use."
        Case "13"
            Return "13 = Windows cannot verify this device's resources."
        Case "14"
            Return "14 = This device cannot work properly until you restart your computer."
        Case "15"
            Return "15 = This device is not working properly because there is probably a re-enumeration problem."
        Case "16"
            Return "16 = Windows cannot identify all the resources this device uses."
        Case "17"
            Return "17 = This device is asking for an unknown resource type."
        Case "18"
            Return "18 = Reinstall the drivers for this device."
        Case "19"
            Return "19 = Failure using the VxD loader."
        Case "20"
            Return "20 = Your registry might be corrupted."
        Case "21"
            Return "21 = System failure: Try changing the driver for this device. If that does not work, see your hardware documentation. Windows is removing this device."
        Case "22"
            Return "22 = This device is disabled."
        Case "23"
            Return "23 = System failure: Try changing the driver for this device. If that doesn't work, see your hardware documentation."
        Case "24"
            Return "24 = This device is not present, is not working properly, or does not have all its drivers installed."
        Case "25"
            Return "25 = Windows is still setting up this device."
        Case "26"
            Return "26 = Windows is still setting up this device."
        Case "27"
            Return "27 = This device does not have valid log configuration."
        Case "28"
            Return "28 = The drivers for this device are not installed."
        Case "29"
            Return "29 = This device is disabled because the firmware of the device did not give it the required resources."
        Case "30"
            Return "30 = This device is using an Interrupt Request (IRQ) resource that another device is using."
        Case "31"
            Return "31 = This device is not working properly because Windows cannot load the drivers required for this device."
        Case Else
            Return $value&" = ???"
    EndSwitch
EndFunc

Func Win32_Battery_PropertyValues_StatusInfo( $value )
    Switch $value
        Case "1"
            Return "1 = Other"
        Case "2"
            Return "2 = Unknown"
        Case "3"
            Return "3 = Enabled"
        Case "4"
            Return "4 = Disabled"
        Case "5"
            Return "5 = Not Applicable"
        Case Else
            Return $value&" = ???"
    EndSwitch
EndFunc


#EndRegion # ValueToDescription Functions #

Func _nice_COMerrorHandler($i = 0)
    If $i == 1 Then
        Dim $_nice_COMerrorArray[301][9]
        $_nice_COMerrorArray[0][0] = 0
        $_nice_COMerrorObj = ObjEvent("AutoIt.Error", "_nice_COMerrorHandler")
        Return
    EndIf
    If $i == 2 Then
        If Not @Compiled Then
            Local $n = 0, $c = 0, $s = FileRead(@ScriptFullPath)
            Local $a = StringSplit($s, @CRLF, 1)
            For $n = 1 To $_nice_COMerrorArray[0][0]
                If Int($_nice_COMerrorArray[$n][7]) > $a[0] Then ContinueLoop
                $_nice_COMerrorArray[$n][8] = StringStripWS($a[Int($_nice_COMerrorArray[$n][7])], 3)
            Next
            If StringInStr($s, "; only for the ANSI compiled version" & @CRLF) Then
                For $n = 1 To $a[0]
                    If StringInStr($a[$n], "; only for the ANSI compiled version") Then $c += 1
                    If $n > 50 Then ExitLoop
                Next
                For $n = 1 To $_nice_COMerrorArray[0][0]
                    $_nice_COMerrorArray[$n][7] = $_nice_COMerrorArray[$n][7] - $c
                Next
            EndIf
        EndIf
        $_nice_COMerrorArray[1][0] = ""
        ReDim $_nice_COMerrorArray[$_nice_COMerrorArray[0][0] + 1][9]
        _ArrayDisplay($_nice_COMerrorArray, "ScriptOMatic - COM Errors intercepted ( the script will continue after this screen )")
        Return
    EndIf
    If $_nice_COMerrorArray[0][0] = 300 Then
        $_nice_COMerrorArray[0][8] = "ScriptLine: only first 300 errors shown !!!"
        Return
    EndIf
    If StringInStr($_nice_COMerrorArray[1][0], "|" & $_nice_COMerrorObj.scriptline & "|") Then Return
    $i = $_nice_COMerrorArray[0][0] + 1
    $_nice_COMerrorArray[0][0] = $i
    $_nice_COMerrorArray[$i][1] = "0x" & Hex($_nice_COMerrorObj, 8)
    $_nice_COMerrorArray[$i][2] = $_nice_COMerrorObj.windescription
    $_nice_COMerrorArray[$i][3] = $_nice_COMerrorObj.source
    $_nice_COMerrorArray[$i][4] = $_nice_COMerrorObj.helpfile
    $_nice_COMerrorArray[$i][5] = $_nice_COMerrorObj.helpcontext
    $_nice_COMerrorArray[$i][6] = $_nice_COMerrorObj.lastdllerror
    $_nice_COMerrorArray[$i][7] = $_nice_COMerrorObj.scriptline
    $_nice_COMerrorArray[1][0] = $_nice_COMerrorArray[1][0] & "|" & $_nice_COMerrorObj.scriptline & "|"
    If $i == 1 Then
        $_nice_COMerrorArray[0][1] = "ErrorNumber:"
        $_nice_COMerrorArray[0][2] = "WinDescription:"
        $_nice_COMerrorArray[0][3] = "Source:"
        $_nice_COMerrorArray[0][4] = "HelpFile:"
        $_nice_COMerrorArray[0][5] = "HelpContext:"
        $_nice_COMerrorArray[0][6] = "LastDLLerror:"
        $_nice_COMerrorArray[0][7] = "ScriptLineNumber:"
        $_nice_COMerrorArray[0][8] = "ScriptLine:"
    EndIf
EndFunc   ;==>_nice_COMerrorHandler


#comments-start

List of all the Properties and Methods for \root\CIMV2:Win32_Battery


Win32_Battery Class Qualifiers
------------------------------

1. Description = The Win32_Battery class represents a battery connected to the computer system. This class applies to both batteries in Laptop Systems and other internal/external batteries.
2. dynamic = -1
3. Locale = 1033
4. provider = CIMWin32
5. UUID = {8502C4B9-5FBB-11D2-AAC1-006008C78BC7}


Win32_Battery Class Properties and Property Qualifiers
------------------------------------------------------

1. Availability
1.1. CIMTYPE = uint16
1.2. Description = The availability and status of the device.  For example, the Availability property indicates that the device is running and has full power (value=3), or is in a warning (4), test (5), degraded (10) or power save state (values 13-15 and 17). Regarding the power saving states, these are defined as follows: Value 13 ("Power Save - Unknown") indicates that the device is known to be in a power save mode, but its exact status in this mode is unknown; 14 ("Power Save - Low Power Mode") indicates that the device is in a power save state but still functioning, and may exhibit degraded performance; 15 ("Power Save - Standby") describes that the device is not functioning but could be brought to full power 'quickly'; and value 17 ("Power Save - Warning") indicates that the device is in a warning state, though also in a power save mode.
1.3. MappingStrings = MIF.DMTF|Operational State|003.5,MIB.IETF|HOST-RESOURCES-MIB.hrDeviceStatus
1.4. read = -1
1.5. ValueMap = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21
1.6. Values = Other,Unknown,Running/Full Power,Warning,In Test,Not Applicable,Power Off,Off Line,Off Duty,Degraded,Not Installed,Install Error,Power Save - Unknown,Power Save - Low Power Mode,Power Save - Standby,Power Cycle,Power Save - Warning,Paused,Not Ready,Not Configured,Quiesced

2. BatteryRechargeTime
2.1. CIMTYPE = uint32
2.2. DEPRECATED = -1
2.3. Description = The BatteryRechargeTime property indicates the time required to fully charge the battery. 
The BatteryRechargeTime property has been deprecated.  There is no replacementvalue and this property is now considered obsolete.
2.4. MappingStrings = HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services|RechargeRate
2.5. read = -1
2.6. Units = minutes

3. BatteryStatus
3.1. CIMTYPE = uint16
3.2. Description = Description of the battery's charge status. Values such as "Fully Charged" (value=3) or "Partially Charged" (11) can be specified. The value, 10, is not valid in the CIM Schema since in DMI it represents that no battery is installed. In this case, this object should not be instantiated.
3.3. MappingStrings = MIF.DMTF|Portable Battery|002.14
3.4. read = -1
3.5. ValueMap = 1,2,3,4,5,6,7,8,9,10,11
3.6. Values = Other,Unknown,Fully Charged,Low,Critical,Charging,Charging and High,Charging and Low,Charging and Critical,Undefined,Partially Charged

4. Caption
4.1. CIMTYPE = string
4.2. Description = The Caption property is a short textual description (one-line string) of the object.
4.3. MaxLen = 64
4.4. read = -1

5. Chemistry
5.1. CIMTYPE = uint16
5.2. Description = An enumeration that describes the battery's chemistry.
5.3. MappingStrings = MIF.DMTF|Portable Battery|002.7
5.4. read = -1
5.5. ValueMap = 1,2,3,4,5,6,7,8
5.6. Values = Other,Unknown,Lead Acid,Nickel Cadmium,Nickel Metal Hydride,Lithium-ion,Zinc air,Lithium Polymer

6. ConfigManagerErrorCode
6.1. CIMTYPE = uint32
6.2. Description = Indicates the Win32 Configuration Manager error code.  The following values may be returned: 
0      This device is working properly. 
1      This device is not configured correctly. 
2      Windows cannot load the driver for this device. 
3      The driver for this device might be corrupted, or your system may be running low on memory or other resources. 
4      This device is not working properly. One of its drivers or your registry might be corrupted. 
5      The driver for this device needs a resource that Windows cannot manage. 
6      The boot configuration for this device conflicts with other devices. 
7      Cannot filter. 
8      The driver loader for the device is missing. 
9      This device is not working properly because the controlling firmware is reporting the resources for the device incorrectly. 
10     This device cannot start. 
11     This device failed. 
12     This device cannot find enough free resources that it can use. 
13     Windows cannot verify this device's resources. 
14     This device cannot work properly until you restart your computer. 
15     This device is not working properly because there is probably a re-enumeration problem. 
16     Windows cannot identify all the resources this device uses. 
17     This device is asking for an unknown resource type. 
18     Reinstall the drivers for this device. 
19     Your registry might be corrupted. 
20     Failure using the VxD loader. 
21     System failure: Try changing the driver for this device. If that does not work, see your hardware documentation. Windows is removing this device. 
22     This device is disabled. 
23     System failure: Try changing the driver for this device. If that doesn't work, see your hardware documentation. 
24     This device is not present, is not working properly, or does not have all its drivers installed. 
25     Windows is still setting up this device. 
26     Windows is still setting up this device. 
27     This device does not have valid log configuration. 
28     The drivers for this device are not installed. 
29     This device is disabled because the firmware of the device did not give it the required resources. 
30     This device is using an Interrupt Request (IRQ) resource that another device is using. 
31     This device is not working properly because Windows cannot load the drivers required for this device.
6.3. read = -1
6.4. ValueMap = 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
6.5. Values = This device is working properly.,This device is not configured correctly.,Windows cannot load the driver for this device.,The driver for this device might be corrupted, or your system may be running low on memory or other resources.,This device is not working properly. One of its drivers or your registry might be corrupted.,The driver for this device needs a resource that Windows cannot manage.,The boot configuration for this device conflicts with other devices.,Cannot filter.,The driver loader for the device is missing.,This device is not working properly because the controlling firmware is reporting the resources for the device incorrectly.,This device cannot start.,This device failed.,This device cannot find enough free resources that it can use.,Windows cannot verify this device's resources.,This device cannot work properly until you restart your computer.,This device is not working properly because there is probably a re-enumeration problem.,Windows cannot identify all the resources this device uses.,This device is asking for an unknown resource type.,Reinstall the drivers for this device.,Failure using the VxD loader.,Your registry might be corrupted.,System failure: Try changing the driver for this device. If that does not work, see your hardware documentation. Windows is removing this device.,This device is disabled.,System failure: Try changing the driver for this device. If that doesn't work, see your hardware documentation.,This device is not present, is not working properly, or does not have all its drivers installed.,Windows is still setting up this device.,Windows is still setting up this device.,This device does not have valid log configuration.,The drivers for this device are not installed.,This device is disabled because the firmware of the device did not give it the required resources.,This device is using an Interrupt Request (IRQ) resource that another device is using.,This device is not working properly because Windows cannot load the drivers required for this device.

7. ConfigManagerUserConfig
7.1. CIMTYPE = boolean
7.2. Description = Indicates whether the device is using a user-defined configuration.
7.3. read = -1

8. CreationClassName
8.1. CIM_Key = -1
8.2. CIMTYPE = string
8.3. Description = CreationClassName indicates the name of the class or the subclass used in the creation of an instance. When used with the other key properties of this class, this property allows all instances of this class and its subclasses to be uniquely identified.
8.4. read = -1

9. Description
9.1. CIMTYPE = string
9.2. Description = The Description property provides a textual description of the object. 
9.3. read = -1

10. DesignCapacity
10.1. CIMTYPE = uint32
10.2. Description = The design capacity of the battery in milliwatt-hours. If this property is not supported, enter 0.
10.3. MappingStrings = MIF.DMTF|Portable Battery|002.8
10.4. read = -1
10.5. Units = milliwatt-hours

11. DesignVoltage
11.1. CIMTYPE = uint64
11.2. Description = The design voltage of the battery in millivolts. If this attribute is not supported, enter 0.
11.3. MappingStrings = MIF.DMTF|Portable Battery|002.9
11.4. read = -1
11.5. Units = millivolts

12. DeviceID
12.1. CIM_Key = -1
12.2. CIMTYPE = string
12.3. Description = The DeviceID property contains a string identifying the battery.
Example: Internal Battery
12.4. key = -1
12.5. MappingStrings = WMI
12.6. Override = DeviceId
12.7. read = -1

13. ErrorCleared
13.1. CIMTYPE = boolean
13.2. Description = ErrorCleared is a boolean property indicating that the error reported in LastErrorCode property is now cleared.
13.3. read = -1

14. ErrorDescription
14.1. CIMTYPE = string
14.2. Description = ErrorDescription is a free-form string supplying more information about the error recorded in LastErrorCode property, and information on any corrective actions that may be taken.
14.3. read = -1

15. EstimatedChargeRemaining
15.1. CIMTYPE = uint16
15.2. Description = An estimate of the percentage of full charge remaining.
15.3. read = -1
15.4. Units = percent

16. EstimatedRunTime
16.1. CIMTYPE = uint32
16.2. Description = EstimatedRunTime is an estimate in minutes of the time to battery charge depletion under the present load conditions if the utility power is off, or lost and remains off, or a Laptop is disconnected from a power source.
16.3. MappingStrings = MIF.DMTF|Portable Battery|002.15
16.4. read = -1
16.5. Units = minutes

17. ExpectedBatteryLife
17.1. CIMTYPE = uint32
17.2. DEPRECATED = -1
17.3. Description = The ExpectedBatteryLife property indicates the amount of time it takes to completely drain the battery after it has been fully charged. 
The ExpectedBatteryLife property has been deprecated.  There is no replacementvalue and this property is now considered obsolete.
17.4. MappingStrings = HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services|BatteryLife
17.5. read = -1
17.6. Units = minutes

18. ExpectedLife
18.1. CIMTYPE = uint32
18.2. Description = Indicates the battery's expected lifetime in minutes, assuming that the battery is fully charged. This property represents the total expected life of the battery, not its current remaining life, which is indicated by the EstimatedRunTime property. 
18.3. read = -1
18.4. Units = minutes

19. FullChargeCapacity
19.1. CIMTYPE = uint32
19.2. Description = The full charge capacity of the battery in milliwatt-hours. Comparison of this value to the DesignCapacity property determines when the battery requires replacement.  A battery's end of life is typically when the FullChargeCapacity property falls below 80% of the DesignCapacity property. If this property is not supported, enter 0.
19.3. MappingStrings = MIF.DMTF|Portable Battery|002.11
19.4. read = -1
19.5. Units = milliwatt-hours

20. InstallDate
20.1. CIMTYPE = datetime
20.2. Description = The InstallDate property is datetime value indicating when the object was installed. A lack of a value does not indicate that the object is not installed.
20.3. MappingStrings = MIF.DMTF|ComponentID|001.5
20.4. read = -1

21. LastErrorCode
21.1. CIMTYPE = uint32
21.2. Description = LastErrorCode captures the last error code reported by the logical device.
21.3. read = -1

22. MaxRechargeTime
22.1. CIMTYPE = uint32
22.2. Description = MaxRechargeTime indicates the maximum time, in minutes, to fully charge the battery. This property represents the time to recharge a fully depleted battery, not the current remaining charging time, which is indicated in the TimeToFullCharge property. 
22.3. read = -1
22.4. Units = minutes

23. Name
23.1. CIMTYPE = string
23.2. Description = The Name property defines the label by which the object is known. When subclassed, the Name property can be overridden to be a Key property.
23.3. read = -1

24. PNPDeviceID
24.1. CIMTYPE = string
24.2. Description = Indicates the Win32 Plug and Play device ID of the logical device.  Example: *PNP030b
24.3. read = -1

25. PowerManagementCapabilities
25.1. CIMTYPE = uint16
25.2. Description = Indicates the specific power-related capabilities of the logical device. The array values, 0="Unknown", 1="Not Supported" and 2="Disabled" are self-explanatory. The value, 3="Enabled" indicates that the power management features are currently enabled but the exact feature set is unknown or the information is unavailable. "Power Saving Modes Entered Automatically" (4) describes that a device can change its power state based on usage or other criteria. "Power State Settable" (5) indicates that the SetPowerState method is supported. "Power Cycling Supported" (6) indicates that the SetPowerState method can be invoked with the PowerState input variable set to 5 ("Power Cycle"). "Timed Power On Supported" (7) indicates that the SetPowerState method can be invoked with the PowerState input variable set to 5 ("Power Cycle") and the Time parameter set to a specific date and time, or interval, for power-on.
25.3. read = -1
25.4. Values = Unknown,Not Supported,Disabled,Enabled,Power Saving Modes Entered Automatically,Power State Settable,Power Cycling Supported,Timed Power On Supported

26. PowerManagementSupported
26.1. CIMTYPE = boolean
26.2. Description = Boolean indicating that the Device can be power managed - ie, put into a power save state. This boolean does not indicate that power management features are currently enabled, or if enabled, what features are supported. Refer to the PowerManagementCapabilities array for this information. If this boolean is false, the integer value 1, for the string, "Not Supported", should be the only entry in the PowerManagementCapabilities array.
26.3. read = -1

27. SmartBatteryVersion
27.1. CIMTYPE = string
27.2. Description = The Smart Battery Data Specification version number supported by this battery. If the battery does not support this function, the value should be left blank.
27.3. MappingStrings = MIF.DMTF|Portable Battery|002.10
27.4. MaxLen = 64
27.5. read = -1

28. Status
28.1. CIMTYPE = string
28.2. Description = The Status property is a string indicating the current status of the object. Various operational and non-operational statuses can be defined. Operational statuses are "OK", "Degraded" and "Pred Fail". "Pred Fail" indicates that an element may be functioning properly but predicting a failure in the near future. An example is a SMART-enabled hard drive. Non-operational statuses can also be specified. These are "Error", "Starting", "Stopping" and "Service". The latter, "Service", could apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is on-line, yet the managed element is neither "OK" nor in one of the other states.
28.3. MaxLen = 10
28.4. read = -1
28.5. ValueMap = OK,Error,Degraded,Unknown,Pred Fail,Starting,Stopping,Service,Stressed,NonRecover,No Contact,Lost Comm
28.6. Values = OK,Error,Degraded,Unknown,Pred Fail,Starting,Stopping,Service,Stressed,NonRecover,No Contact,Lost Comm

29. StatusInfo
29.1. CIMTYPE = uint16
29.2. Description = StatusInfo is a string indicating whether the logical device is in an enabled (value = 3), disabled (value = 4) or some other (1) or unknown (2) state. If this property does not apply to the logical device, the value, 5 ("Not Applicable"), should be used.
29.3. MappingStrings = MIF.DMTF|Operational State|003.3
29.4. read = -1
29.5. ValueMap = 1,2,3,4,5
29.6. Values = Other,Unknown,Enabled,Disabled,Not Applicable

30. SystemCreationClassName
30.1. CIM_Key = -1
30.2. CIMTYPE = string
30.3. Description = The scoping System's CreationClassName.
30.4. Propagated = CIM_System.CreationClassName
30.5. read = -1

31. SystemName
31.1. CIM_Key = -1
31.2. CIMTYPE = string
31.3. Description = The scoping System's Name.
31.4. Propagated = CIM_System.Name
31.5. read = -1

32. TimeOnBattery
32.1. CIMTYPE = uint32
32.2. Description = TimeOnBattery indicates the elapsed time in seconds since the computer system's UPS last switched to battery power, or the time since the system or UPS was last restarted, whichever is less. Zero shall be returned if the battery is 'on line'.
32.3. read = -1
32.4. Units = seconds

33. TimeToFullCharge
33.1. CIMTYPE = uint32
33.2. Description = The remaining time to charge the battery fully in minutes at the current charging rate and usage.
33.3. MappingStrings = MIF.DMTF|Portable Battery|002.16
33.4. read = -1
33.5. Units = minutes


Win32_Battery Class Methods and Method Qualifiers
-------------------------------------------------

1. SetPowerState
1.1. Description = SetPowerState defines the desired power state for a logical device and when a device should be put into that state. The desired power state is specified by setting the PowerState parameter to one of the following integer values: 1="Full Power", 2="Power Save - Low Power Mode", 3="Power Save - Standby", 4="Power Save - Other", 5="Power Cycle" or 6="Power Off". The Time parameter (for all state changes, except 5, "Power Cycle") indicates when the power state should be set, either as a regular date-time value or as an interval value (where the interval begins when the method invocation is received). When the PowerState parameter is equal to 5, "Power Cycle", the Time parameter indicates when the device should power on again. Power off is immediate. SetPowerState should return 0 if successful, 1 if the specified PowerState and Time request is not supported, and some other value if any other error occurred. In a subclass, the set of possible return codes could be specified, using a ValueMap qualifier on the method. The strings to which the ValueMap contents are 'translated' may also be specified in the subclass as a Values array qualifier.

2. Reset
2.1. Description = Requests a reset of the logical device. The return value should be 0 if the request was successfully executed, 1 if the request is not supported and some other value if an error occurred.

#comments-end

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello. I have no so much time to look into. But I think this is what you're looking for.

 

Saludos

Edited by Danyfirex

Share this post


Link to post
Share on other sites

When you say heavier to run, what exactly do you mean by that?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Just now, BrewManNH said:

When you say heavier to run, what exactly do you mean by that?

WMI has to run an exe that is slow(er) than a DLL call. Am I wrong ?
I can use the DLL as in https://www.autoitscript.com/forum/topic/89539-battery-checker/ and then run the WMI once a minute to folowup oneach UPS status, but, does not hurt to ask. Maybe, there is a way. I don't know.

Share this post


Link to post
Share on other sites

I can't see that the issue of how long it takes to run one vs the other would have much effect on the usefullness of the method used vs another. Also, I'm almost certain that WMI has to be running before the WMI object can be gotten, so in most cases it's already started on your computer.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
14 minutes ago, BrewManNH said:

I can't see that the issue of how long it takes to run one vs the other would have much effect on the usefullness of the method used vs another. Also, I'm almost certain that WMI has to be running before the WMI object can be gotten, so in most cases it's already started on your computer.

ok, so you do not have an answer to my question.
My question is: is there a DLL way ( as in the WinAPI call ) to get independent reading as WMI does ?

Share this post


Link to post
Share on other sites

What research have you done that would make you think that calling a function in a DLL is faster/slower/the same as connecting to an object of an already running program? Just wondering.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
2 hours ago, argumentum said:

ok, so you do not have an answer to my question.
My question is: is there a DLL way ( as in the WinAPI call ) to get independent reading as WMI does ?

For a remote machine I am assuming?  Not that I'm aware of.  A cheap hack you could do is make a stand-alone script to output the result/value to the console and use a remote execution tool like psexec.  I'd think the overhead would be comparable to WMI over time though.

Share this post


Link to post
Share on other sites

@BrewManNH and @spudw2k 
Well, yes, I have 3 PCs, 1 SAN and other things hooked up. My idea is to have the PC I use most, figure out when is time to call it quits and shut down everything.
To do the shout down, the PC sensing the remaining power of the most drained UPS, and broadcasting UDP something that every PC can receive and initiate its own shou down.
Since I never had 2 UPS at once, I looked around to see what can I use. So found that _WinAPI_GetSystemPowerStatus() gives me an average reading. Tried the WMI and found it gives me independent values ( by which I deduced that GetSystemPowerStatus was averaging the values ).
So my question was: is there as DLL call to do what WMI is doing ?, and therefore my  post. I'm not stuck. I'm curious, I'm weighing my options.
My next unresearched question is, "how do I tell the WDEX4100 to shut down".

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