; https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-system_power_status?redirectedfrom=MSDN
Define.SYSTEM_POWER_STATUS SPS
GetSystemInfo_(SPS)
Debug "SPS\ACLineStatus: " + SPS\ACLineStatus ; Với PC/Desktop, trả về 0. Với laptop, nếu trả về 0, nghĩa là laptop không cắm dây sạc
Debug "SPS\BatteryFlag: " + SPS\BatteryFlag ; Với PC/Desktop, trả về 0.
; https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getsystempowerstatus?redirectedfrom=MSDN
; Truy xuất trạng thái nguồn của hệ thống.
; Trạng thái cho biết hệ thống đang chạy bằng nguồn AC hay DC, pin hiện đang sạc hay không,
; thời lượng pin còn lại là bao nhiêu và chế độ tiết kiệm pin đang bật hay tắt.
Debug "SPS\GetSystemPowerStatus_: " + GetSystemPowerStatus_(SPS)
If GetSystemPowerStatus_(SPS) = #True
Debug "PowerStatus is available."
Else
Debug "Powerstatus cannot be detected."
EndIf
PC: Windows 10 x64, 8GB RAM. PB ver: 6.x
--
I love PB5 vs PB6
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Define.SYSTEM_POWER_STATUS SPS
If GetSystemPowerStatus_(@SPS) = #True
Debug "PowerStatus is available."
Debug "SPS\ACLineStatus: " + SPS\ACLineStatus ; Với PC/Desktop, trả về 0. Với laptop, nếu trả về 0, nghĩa là laptop không cắm dây sạc
Debug "SPS\BatteryFlag: " + SPS\BatteryFlag ; Với PC/Desktop, trả về 0.
Else
Debug "Powerstatus cannot be detected."
EndIf
You can't reliably test if a PC is a laptop or desktop by checking the battery/charging status. Case in point: I use a laptop that doesn't have a battery, so these tests incorrectly say it's a desktop due to it being constantly plugged into AC power. You'll need to find another non-battery method.
BarryG wrote: Fri Jun 21, 2024 8:23 am
You can't reliably test if a PC is a laptop or desktop by checking the battery/charging status. Case in point: I use a laptop that doesn't have a battery, so these tests incorrectly say it's a desktop due to it being constantly plugged into AC power. You'll need to find another non-battery method.