Is this a laptop or Pc? (detection)
Don't do this. Instead do feature detection on the features that you need this for. There isn't really a sharp line between laptops and pc's, so you can never get this right. The only real difference is in the shape of the box, which is not a property the rest of the hardware knows about.
You can check for laptop processors, but this does not guarantee that it is a laptop since these are also used in some "silent" computers or mini-pc's. In fact, laptop parts can usually be used in a normal computer.
You can check for laptop processors, but this does not guarantee that it is a laptop since these are also used in some "silent" computers or mini-pc's. In fact, laptop parts can usually be used in a normal computer.
Some (older) (performance) laptops don't use mobile versions, some (newer) (energy saving) desktops do use mobile versions, and even full mobile chipsets.
A user toggle might be your best option
A user toggle might be your best option
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
- doctorized
- Addict

- Posts: 882
- Joined: Fri Mar 27, 2009 9:41 am
- Location: Athens, Greece
Re: Is this a laptop or Pc? (detection)
Sorry for bringing back to life this old post but is there any good way to detect if a computer is laptop or desktop without using WMI or battery info or CPU name?
Re: Is this a laptop or Pc? (detection)
Hi doctorized.
The preferred solution for me was the following.
The preferred solution for me was the following.
Code: Select all
Procedure IsLaptop()
Laptop.SYSTEM_POWER_STATUS:GetSystemPowerStatus_(Laptop)
If Laptop\ACLineStatus=0 Or (Laptop\BatteryFlag=>0 And Laptop\BatteryFlag=<8) Or (Laptop\BatteryLifePercent=>0 And Laptop\BatteryLifePercent=<100) Or Laptop\BatteryLifeTime=>0
ProcedureReturn #True
EndIf
EndProcedure
Debug IsLaptop()ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Is this a laptop or Pc? (detection)
There are a ton of laptops now that are fitted with a 'desktop' CPU and a full-blown graphics card too. I don't know of a hardware component detection that is going to be reliable. Possibly a better route might be to examine the manufactures' name for the PC, but really the best bet is to simply ask the User during the install of the app.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Is this a laptop or Pc? (detection)
The best way to do this is check the WMI System eclosure type, I am at work right now so can't script this up into Commate (However I have done it many times)
Heres the VB that needs to be translated :
This will then give you one of the following :
Forget the CPU / battery approach!
Heres the VB that needs to be translated :
Code: Select all
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colChassis = objWMIService.ExecQuery _
("SELECT * FROM Win32_SystemEnclosure")
For Each objChassis in colChassis
For Each intType in objChassis.ChassisTypes
Wscript.Echo intType
Next
Next
Code: Select all
1 Other
2 Unknown
3 Desktop
4 Low Profile Desktop
5 Pizza Box
6 Mini Tower
7 Tower
8 Portable
9 Laptop
10 Notebook
11 Hand Held
12 Docking Station
13 All in One
14 Sub Notebook
15 Space-Saving
16 Lunch Box
17 Main System Chassis
18 Expansion Chassis
19 Sub Chassis
20 Bus Expansion Chassis
21 Peripheral Chassis
22 Storage Chassis
23 Rack Mount Chassis
24 Sealed-Case PC----
R Tape loading error, 0:1
R Tape loading error, 0:1
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Is this a laptop or Pc? (detection)
Will only work if it is supported by the manufacturer. There isn't any point at all in using any device information code unless it can deliver the exact information 99.99% of the time. What is wrong with asking the User? That will work!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Is this a laptop or Pc? (detection)
It's a perfectly acceptable way of determining hardware type. I've yet to run into a manufacturers model that doesn't conform. I've spent years reporting on 1000s of devices using this method as part of the criteria. Never ran into any issues, so for me it was 100% perfect.IdeasVacuum wrote:Will only work if it is supported by the manufacturer. There isn't any point at all in using any device information code unless it can deliver the exact information 99.99% of the time. What is wrong with asking the User? That will work!
Use it to pre-select the user's answer, then get them to confirm.
----
R Tape loading error, 0:1
R Tape loading error, 0:1
Re: Is this a laptop or Pc? (detection)
I've done some research, and done up some codes.
Of course I wanted to improve my existing code...
Code: Select all
Structure BATTERY_REPORTING_SCALE
Granularity.l
Capacity.l
EndStructure
Structure SYSTEM_POWER_CAPABILITIES
PowerButtonPresent.b
SleepButtonPresent.b
LidPresent.b
SystemS1.b
SystemS2.b
SystemS3.b
SystemS4.b
SystemS5.b
HiberFilePresent.b
FullWake.b
VideoDimPresent.b
ApmPresent.b
UpsPresent.b
ThermalControl.b
ProcessorThrottle.b
ProcessorMinThrottle.b
ProcessorMaxThrottle.b
FastSystemS4.b
HiberBoot.b
WakeAlarmPresent.b
AoAc.b
DiskSpinDown.b
spare3.b[8]
SystemBatteriesPresent.b
BatteriesAreShortTerm.b
BatteryScale.BATTERY_REPORTING_SCALE[3]
AcOnLineWake.b
SoftLidWake.b
RtcWake.b
MinDeviceWakeState.b
DefaultLowLatencyWake.b
EndStructure ;: Global PowrProf.SYSTEM_POWER_CAPABILITIES
Prototype PowerDeterminePlatformRole()
Global PowerDeterminePlatformRole.PowerDeterminePlatformRole
Prototype GetPwrCapabilities(lpSystemPowerCapabilities)
Global GetPwrCapabilities.GetPwrCapabilities
Procedure.i powrprof_LoadDLL()
Protected hDLL.i
hDLL = OpenLibrary(#PB_Any, "powrprof.dll")
If hDLL <> 0
PowerDeterminePlatformRole = GetFunction(hDLL, "PowerDeterminePlatformRole")
GetPwrCapabilities = GetFunction(hDLL, "GetPwrCapabilities")
ProcedureReturn hDLL
EndIf
ProcedureReturn #False
EndProcedure
#PlatformRoleDesktop = 1
#PlatformRoleMobile = 2
Procedure IsMobilePlatform()
Protected fIsMobilePlatform.b = #False, iRole.b
IsPowrProf = powrprof_LoadDLL()
If IsPowrProf
; // Check If the operating system determines
; // that the computer is a mobile computer.
iRole = PowerDeterminePlatformRole()
fIsMobilePlatform = Bool(#PlatformRoleMobile = iRole)
If #PlatformRoleMobile = iRole
fIsMobilePlatform = #True
ElseIf #PlatformRoleDesktop = iRole
; // Can happen when a battery is not plugged into a laptop
powerCapabilities.SYSTEM_POWER_CAPABILITIES
If GetPwrCapabilities(powerCapabilities)
; // Check If a battery exists, And it is Not For a UPS.
; // Note that SystemBatteriesPresent is set on a laptop even If the battery is unplugged.
fIsMobilePlatform = Bool(#True =powerCapabilities\SystemBatteriesPresent And #False = powerCapabilities\BatteriesAreShortTerm)
EndIf
EndIf
CloseLibrary(IsPowrProf)
ProcedureReturn fIsMobilePlatform
EndIf
EndProcedure
; Debug IsMobilePlatform()
MessageRequester("IsMobilePlatform() ?", "Answer Is.... "+IsMobilePlatform(), #PB_MessageRequester_Ok)Of course I wanted to improve my existing code...
Code: Select all
Structure BATTERY_REPORTING_SCALE
Granularity.l
Capacity.l
EndStructure
Structure SYSTEM_POWER_CAPABILITIES
PowerButtonPresent.b
SleepButtonPresent.b
LidPresent.b
SystemS1.b
SystemS2.b
SystemS3.b
SystemS4.b
SystemS5.b
HiberFilePresent.b
FullWake.b
VideoDimPresent.b
ApmPresent.b
UpsPresent.b
ThermalControl.b
ProcessorThrottle.b
ProcessorMinThrottle.b
ProcessorMaxThrottle.b
FastSystemS4.b
HiberBoot.b
WakeAlarmPresent.b
AoAc.b
DiskSpinDown.b
spare3.b[8]
SystemBatteriesPresent.b
BatteriesAreShortTerm.b
BatteryScale.BATTERY_REPORTING_SCALE[3]
AcOnLineWake.b
SoftLidWake.b
RtcWake.b
MinDeviceWakeState.b
DefaultLowLatencyWake.b
EndStructure ;: Global PowrProf.SYSTEM_POWER_CAPABILITIES
Prototype GetPwrCapabilities(lpSystemPowerCapabilities)
Global GetPwrCapabilities.GetPwrCapabilities
Procedure IsMobilePlatform_Ex()
PowrProf.SYSTEM_POWER_CAPABILITIES
Protected hDLL.i, IsOK.l = -1
hDLL = OpenLibrary(#PB_Any, "powrprof.dll")
If hDLL <> 0
GetPwrCapabilities = GetFunction(hDLL, "GetPwrCapabilities")
If GetPwrCapabilities(PowrProf)
IsOK = Bool((#True =PowrProf\SystemBatteriesPresent And #False = PowrProf\BatteriesAreShortTerm) Or #True = PowrProf\LidPresent)
EndIf
CloseLibrary(hDLL)
ProcedureReturn IsOK
EndIf
EndProcedure
Procedure IsMobilePlatform()
MobilePlatform.SYSTEM_POWER_STATUS:GetSystemPowerStatus_(MobilePlatform)
If MobilePlatform\ACLineStatus = 0 Or (MobilePlatform\BatteryFlag=>0 And MobilePlatform\BatteryFlag=<10) Or
(MobilePlatform\BatteryLifePercent=>0 And MobilePlatform\BatteryLifePercent=<100) Or (MobilePlatform\BatteryLifeTime=>0)
ProcedureReturn 2
ElseIf IsMobilePlatform_Ex()
ProcedureReturn 1
EndIf
EndProcedure
; Debug IsMobilePlatform()
MessageRequester("IsMobilePlatform() ?", "Answer Is.... "+IsMobilePlatform(), #PB_MessageRequester_Ok)ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
- doctorized
- Addict

- Posts: 882
- Joined: Fri Mar 27, 2009 9:41 am
- Location: Athens, Greece
Re: Is this a laptop or Pc? (detection)
What is the value that I should look at?em_uk wrote:The best way to do this is check the WMI System eclosure type, I am at work right now so can't script this up into Commate (However I have done it many times)
..................
Forget the CPU / battery approach!
@Thunder93: your first code is not running with PB x86, invalid memory access (read error at address 0) for line 95 occurs, but is running fine with PB x64.
Re: Is this a laptop or Pc? (detection)
Didn't observe that problem with either Windows platforms.
Try moving
to the topmost in the procedure Procedure IsMobilePlatform()
Try moving
Code: Select all
powerCapabilities.SYSTEM_POWER_CAPABILITIESCode: Select all
Procedure IsMobilePlatform()
powerCapabilities.SYSTEM_POWER_CAPABILITIES
....ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Re: Is this a laptop or Pc? (detection)
Remember to also test with your laptop battery removed too.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
- doctorized
- Addict

- Posts: 882
- Joined: Fri Mar 27, 2009 9:41 am
- Location: Athens, Greece
Re: Is this a laptop or Pc? (detection)
Now runs ok! In two hours I will have the laptop in my hands to do the tests.Thunder93 wrote:Try moving .... to the topmost in the procedure Procedure IsMobilePlatform()
Re: Is this a laptop or Pc? (detection)
You should be pleased with the results. 
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
- doctorized
- Addict

- Posts: 882
- Joined: Fri Mar 27, 2009 9:41 am
- Location: Athens, Greece
Re: Is this a laptop or Pc? (detection)
I am already pleased with the responses!Thunder93 wrote:You should be pleased with the results.
EDIT: Thunder93's code with IsLaptop() procedure ran to my laptop without battery and returned the same data as in my desktop pc. I took all the data from SYSTEM_POWER_STATUS structure from both computers:
Code: Select all
ACLineStatus = 1
BatteryFlag = 128
BatteryLifePercent = 255
Reserved1 = 0
BatteryLifeTime = 4294967295
BatteryFullLifeTime = 4294967295Also the old code from SFSxOI works fine.
Thanks a lot for your replies!!

