Forum > General
UtilWMI issue - not returning all values.
teco:
Works perfectly.
You can get now information from all Namespaces...
Thaddy:
Just battery level is easy:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program BatteryLevel;{$apptype console}{$mode objfpc}uses SysUtils, Windows; var PowerStatus: TSystemPowerStatus; BatteryLifePercent: Byte; begin if GetSystemPowerStatus(PowerStatus) then begin BatteryLifePercent := PowerStatus.BatteryLifePercent; if BatteryLifePercent <> 255 then WriteLn('Battery level: ', BatteryLifePercent, '%') else WriteLn('Battery level: Unknown'); end else WriteLn('Unable to retrieve battery status'); Readln;end.Code is NOT by me.
On linux you can open the file '/sys/class/power_supply/BAT0/capacity'
if it is available.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program BatteryLevelLinux;{$mode objfpc}{$I-}uses SysUtils; function ReadBatteryLevel: Integer;var BatteryFile: Text; Line: string; BatteryLevel: Integer;begin Assign(BatteryFile, '/sys/class/power_supply/BAT0/capacity'); Reset(BatteryFile); if IOresult <> 0 then begin writeln('Battery not present?'); halt(1); end; ReadLn(BatteryFile, Line); BatteryLevel := StrToInt(Line); Result := BatteryLevel; Close(BatteryFile);end; begin WriteLn('Battery level: ', ReadBatteryLevel, '%');end.That code is by me, but does not work on all systems.....
Navigation
[0] Message Index
[*] Previous page