Page 1 of 1

How can I identify the computer as a Laptop or PC/Desktop.

Posted: Fri Jun 21, 2024 5:58 am
by hoangdiemtinh
I am new to PB. My primary language is not US/UK. I am using Google Translate.

I tried the following code snippets, but could not get the job done.

Please help. Thanks.

Code: Select all

; 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

Re: How can I identify the computer as a Laptop or PC/Desktop.

Posted: Fri Jun 21, 2024 6:34 am
by boddhi
hoangdiemtinh wrote: I am new to PB.
A little off-topic question: Why this signature?
hoangdiemtinh wrote: PC: Windows 10 x64, 8GB RAM. PB ver: 6.x
--
Thorsten Hoeppner (Thorsten1867): PureBasic Modules - PureBasic Programs

Re: How can I identify the computer as a Laptop or PC/Desktop.

Posted: Fri Jun 21, 2024 6:52 am
by infratec
This works for me:

Code: Select all

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

Re: How can I identify the computer as a Laptop or PC/Desktop.

Posted: Fri Jun 21, 2024 8:23 am
by BarryG
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.

Re: How can I identify the computer as a Laptop or PC/Desktop.

Posted: Fri Jun 21, 2024 1:48 pm
by hoangdiemtinh
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.
I found solution at here: https://www.purebasic.fr/english/viewtopic.php?t=38380

Re: How can I identify the computer as a Laptop or PC/Desktop.

Posted: Tue Jun 25, 2024 6:52 am
by Bitblazer
For windows use GetWMIObject to ask for the win32_computersystem property PCSystemType

Checking for battery status, cpu types or using the location api history is not very reliable.

Re: How can I identify the computer as a Laptop or PC/Desktop.

Posted: Tue Jun 25, 2024 11:28 am
by hoangdiemtinh
I appreciate your suggestions.

I need that runs through winAPI or direct PB code. My program also need to run on winPE.