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

Just starting out? Need help? Post your questions and find answers here.
hoangdiemtinh
User
User
Posts: 97
Joined: Wed Nov 16, 2022 1:51 pm

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

Post 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
PC: Windows 10 x64, 8GB RAM. PB ver: 6.x
--
I love PB5 vs PB6 :)
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

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

Post 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
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...
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post 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
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

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

Post 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.
hoangdiemtinh
User
User
Posts: 97
Joined: Wed Nov 16, 2022 1:51 pm

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

Post 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
PC: Windows 10 x64, 8GB RAM. PB ver: 6.x
--
I love PB5 vs PB6 :)
Bitblazer
Enthusiast
Enthusiast
Posts: 766
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

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

Post 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.
hoangdiemtinh
User
User
Posts: 97
Joined: Wed Nov 16, 2022 1:51 pm

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

Post by hoangdiemtinh »

I appreciate your suggestions.

I need that runs through winAPI or direct PB code. My program also need to run on winPE.
PC: Windows 10 x64, 8GB RAM. PB ver: 6.x
--
I love PB5 vs PB6 :)
Post Reply