%_BATTERY returns 0 and others

1590053988086.png

What does the value 0 mean? The same as unknown?
I have also received 9 and 10, but they are not documented.
I assume that such values as 9,10 and 12 can also "appear" as
combinations with 1+8 / 2+8 / 4+8,
i.e. state high + charging, low + charging and critical + charging.
If so, You should mentioned it in the manual.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,175
71
Albuquerque, NM
prospero.unm.edu
I'm pretty sure those three variables all come from here: SYSTEM_POWER_STATUS

"High" is defined as more than 66%; "Low" is less than 33%. So I would guess that, if neither flag is set, the remaining estimated percentage must be somewhere in the range of 33% to 66%. (In your screen shot, it's 36%.)

[edit] Four variables, not three; _ACSTATUS also comes from that structure.
 
So it does. I'd missed that; thanks.
Thanks, so I can update my BatteryState-Function:
Code:
BatteryState=%@IF[%_BATTERY == 128 .AND. %_BATTERYLIFE == unknown .AND. %_BATTERYPERCENT == unknown,^
          No Battery present :-),^
          %@IF[%_BATTERY GE 8,%@FIELD[%@EVAL[%_BATTERY AND 7],Niedrig-Hoch,Hoch,Niedrig,3-N/A,Kritisch] (Wird geladen),^
            %@FIELD[%@EVAL[%_BATTERY AND 7],Niedrig-Hoch,Hoch,Niedrig,3-N/A,Kritisch] ]^
]
But the TCC-Manual could also be updated :-)
 
The 0 value was added by MS (long) after _battery was implemented in TCC.
Yeah, I suspected as much.
That Windows API is pretty decrepit and there are much better & more accurate ways of determining battery info nowadays.
Such as?
WMI ? Pretty extensive study necessary.
Well, I found just these values in TCC very handy, like many things in TCC :smile:
 
May 20, 2008
10,397
77
Syracuse, NY, USA
WMI ? Pretty extensive study necessary.
Not much study is needed to do basic WMI queries with TCC. First try this

Code:
WMIQUERY . "Select * from Win32_battery"
That should show you all that is available (I can't test here because I don't have anything with a battery). Then if you want specific values (like "Status"), try something like this.

Code:
ECHO %@WMI[.,"Select Status from Win32_Battery"]
The Win32_Battery class is documented here. That page has a lot of stuff you're not interested in.

And the "WMI Code Creator" (from Microsoft) can be a big help. There's a download link to it in the help for WMIQUERY.[/code]
 
Aug 23, 2010
560
7
Code:
$ xx.btm
Availability = 2
BatteryStatus = 2
Caption = Internal Battery
Chemistry = 2
CreationClassName = Win32_Battery
Description = Internal Battery
DesignVoltage = 1
DeviceID = Mfr
EstimatedChargeRemaining = 100
EstimatedRunTime = 13
Name =
PowerManagementCapabilities = {1}
PowerManagementSupported = False
Status = OK
SystemCreationClassName = Win32_ComputerSystem
SystemName = DAEMON2
 
Not much study is needed to do basic WMI queries with TCC. First try this
Code:
WMIQUERY . "Select * from Win32_battery"
That should show you all that is available (I can't test here because I don't have anything with a battery). Then if you want specific values (like "Status"), try something like this.
Code:
ECHO %@WMI[.,"Select Status from Win32_Battery"]
The Win32_Battery class is documented here. That page has a lot of stuff you're not interested in.
And the "WMI Code Creator" (from Microsoft) can be a big help. There's a download link to it in the help for WMIQUERY.[/code]
The basis is also not the problem, because I already struggled with WMI and WMIC years ago.
This means that WQL or other queries are not a problem, but the incredible variety of classes and
methods and properties - and all especially the understanding of these. Because the whole thing
is only very inadequately documented.
You can even see it already in the class Win32_Battery.
The page lists 33 properties, some of which have more than 30 values or
States, some are briefly explained, but some are also marked as "deprecated".
The same number of properties and methods (and even more) I get from
Powershell with
Code:
GWMI -namespace root\cimv2 -class win32_battery
In TCC provides me with
WMIQUERY . "Select * from Win32_Battery"
Code:
Availability = 2
BatteryStatus = 2
Caption = Interner Akku
Chemistry = 2
CreationClassName = Win32_Battery
Description = Interner Akku
DesignVoltage = 12069
DeviceID =   TKBSSD17D-22
EstimatedChargeRemaining = 54
EstimatedRunTime = 71582788
Name = D17D-22
PowerManagementCapabilities = {1}
PowerManagementSupported = False
Status = OK
SystemCreationClassName = Win32_ComputerSystem
SystemName = PM_NOTEBOOK-3
so these are only the properties that have a value, that is very
much handier, because it saves me having to use more filters.

Now I have tried it for about three days and with the help of the "Documentation"
I found out that I can only use four properties
Availability , BatteryStatus, EstimatedChargeRemaining and EstimatedRunTime
The others are rather static.
However, in order to bring these properties into a compact line now, I had to create and
develop a real script, for which I created a - admittedly quite complex - alias in TCC
I used:
Code:
BatterieStatus=Echo Ladungsstatus: %_BATTERYPERCENT%%% = ^
  %@IF[%_BATTERY == 128 .AND. %_BATTERYLIFE == unknown .AND. %_BATTERYPERCENT == unknown,^
    No Battery present :-),^
    %@IF[%_BATTERY GE 8,^
        %@FIELD[%@EVAL[%_BATTERY AND 7],Niedrig^<-^>Hoch,Hoch,Niedrig,3-N/A,Kritisch] (Wird geladen),^
        %@FIELD[%@EVAL[%_BATTERY AND 7],Niedrig^<-^>Hoch,Hoch,Niedrig,3-N/A,Kritisch]]]^
  ,%@IF[%_BATTERYLIFE == unknown, Netzbetrieb, Lebensdauer: %@MAKETIME[%_BATTERYLIFE]]
The script looks like this:
Code:
Set Prop=EstimatedChargeRemaining
  Set BatterPercent=%@WMI[.,"Select %prop% from Win32_battery"]

Set Prop=Availability
  Set BattAvail=%@FIELD[",",%@WMI[.,"Select %prop% from Win32_battery"],^
    Null,^
    Other-Irgendwas unklares,^
    Unbekannt,^
    Voll geldaen,^
    Warnung,^
    Im Test,^
    Nicht verfügbar,^
    Ausgeschaltet,^
    Off Line,^
    Außer Dienst,^
    Abgestuft (?),^
    Nichtt installiert,^
    Installationsfehler,^
    Energiesparmodus - Unbekannt,^
    Energiesparmodus - Niedrigverbrauchsmodus,^
    Energiesparmodus - Standby,^
    Leistungszyklus,^
    Energiesparmodus - Warnung,^
    Angehalten,^
    Nicht Bereit,^
    Nichtt Konfiguriert,^
    Ruhezustand]
The WMI_Code Creator is only useful to scan the installed WMI classes. I used it already two years ago
when I tried to learn Powershell and DOT-Net. I even translated the interface in the code so I could use
it in German.

Conclusion:
I stick to my statement: WMI is very extensive and complex and rather poorly documented (probably because
it is so extensive and complex :-) )
but you can get lost very quickly in this jungle !
I prefer TCC, and its internal variables and the ALIAS feature.