Page 2 of 3

Posted: Sat Aug 08, 2009 9:13 am
by Trond
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.

Posted: Sat Aug 08, 2009 10:43 am
by blueznl
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 :-)

Re: Is this a laptop or Pc? (detection)

Posted: Tue Mar 11, 2014 8:42 pm
by doctorized
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)

Posted: Tue Mar 11, 2014 9:09 pm
by Thunder93
Hi doctorized.

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()

Re: Is this a laptop or Pc? (detection)

Posted: Tue Mar 11, 2014 11:00 pm
by IdeasVacuum
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.

Re: Is this a laptop or Pc? (detection)

Posted: Wed Mar 12, 2014 6:12 pm
by em_uk
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 :

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
This will then give you one of the following :

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
Forget the CPU / battery approach!

Re: Is this a laptop or Pc? (detection)

Posted: Wed Mar 12, 2014 7:11 pm
by IdeasVacuum
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!

Re: Is this a laptop or Pc? (detection)

Posted: Thu Mar 13, 2014 2:07 am
by em_uk
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!
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.

Use it to pre-select the user's answer, then get them to confirm.

Re: Is this a laptop or Pc? (detection)

Posted: Thu Mar 13, 2014 8:34 am
by Thunder93
I've done some research, and done up some codes.

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)

Re: Is this a laptop or Pc? (detection)

Posted: Thu Mar 13, 2014 3:24 pm
by doctorized
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!
What is the value that I should look at?

@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)

Posted: Thu Mar 13, 2014 3:42 pm
by Thunder93
Didn't observe that problem with either Windows platforms.
Try moving

Code: Select all

powerCapabilities.SYSTEM_POWER_CAPABILITIES
to the topmost in the procedure Procedure IsMobilePlatform()

Code: Select all

Procedure IsMobilePlatform()
  powerCapabilities.SYSTEM_POWER_CAPABILITIES
  ....

Re: Is this a laptop or Pc? (detection)

Posted: Thu Mar 13, 2014 3:43 pm
by Thunder93
Remember to also test with your laptop battery removed too.

Re: Is this a laptop or Pc? (detection)

Posted: Thu Mar 13, 2014 3:47 pm
by doctorized
Thunder93 wrote:Try moving .... to the topmost in the procedure Procedure IsMobilePlatform()
Now runs ok! In two hours I will have the laptop in my hands to do the tests.

Re: Is this a laptop or Pc? (detection)

Posted: Thu Mar 13, 2014 3:49 pm
by Thunder93
You should be pleased with the results. :)

Re: Is this a laptop or Pc? (detection)

Posted: Thu Mar 13, 2014 3:53 pm
by doctorized
Thunder93 wrote:You should be pleased with the results. :)
I am already pleased with the responses!

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 = 4294967295
The two new codes posted today returned successfully 1 in my laptop (without battery) and 0 in my desktop.
Also the old code from SFSxOI works fine.

Thanks a lot for your replies!! :D