Jump to content

Determine if machine is a desktop or laptop.


Recommended Posts

Is it possible to determine at some point if the installation is beeing run on a laptop or dekstop?

I'm asking cause id like to be able to set powersaving settings, graphical settings, WLAN settings etc. conditionally to if it's a desktop computer or a lappy.

:hello:

Link to comment
Share on other sites


yep - you can do this using a simple WMI query once the windows shell has loaded.

Sample vb script:

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colChassis = objWMIService.ExecQuery _

("Select * from Win32_SystemEnclosure")

For Each objChassis in colChassis

For i = Lbound(objChassis.ChassisTypes) to Ubound(objChassis.ChassisTypes)

Wscript.Echo objChassis.ChassisTypes(i)

Next

Next

---------------------------------------------------------------------

ChassisTypes

Data type: uint16 array

Access type: Read-only

Array of chassis types. This property is inherited from CIM_Chassis.

Value Meaning

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 SubChassis

20 Bus Expansion Chassis

21 Peripheral Chassis

22 Storage Chassis

23 Rack Mount Chassis

24 Sealed-Case PC

Link to comment
Share on other sites

getchassis.vbs

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colChassis = objWMIService.ExecQuery _

("Select * from Win32_SystemEnclosure")

For Each objChassis in colChassis

strType = objChassis.ChassisTypes(i)

Next

If strType = "5" Then

' Pizza box type, so run pizza type chassis commands here via more vbscript code

End If

Link to comment
Share on other sites

Here is A VBS script I found at Hey,Scripting Guy! I added a function for the desktop as a example

of how to do some thing if a match is found.

strComputer = "."

Dim Act

Set Act = CreateObject("Wscript.Shell")

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colChassis = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")

For Each objChassis in colChassis

For Each strChassisType in objChassis.ChassisTypes

Select Case strChassisType

Case 1

Act.Popup "Other" ,5,"Computer Type", 0 + 32

Case 2

Act.Popup "Unknown" ,5,"Computer Type", 0 + 32

Case 3

DeskTop

Case 4

Act.Popup "Low Profile Desktop" ,5,"Computer Type", 0 + 32

Case 5

Act.Popup "Pizza Box" ,5,"Computer Type", 0 + 32

Case 6

Act.Popup "Mini Tower" ,5,"Computer Type", 0 + 32

Case 7

Act.Popup "Tower" ,5,"Computer Type", 0 + 32

Case 8

Act.Popup "Portable" ,5,"Computer Type", 0 + 32

Case 9

Act.Popup "Laptop" ,5,"Computer Type", 0 + 32

Case 10

Act.Popup "Notebook" ,5,"Computer Type", 0 + 32

Case 11

Act.Popup "Handheld" ,5,"Computer Type", 0 + 32

Case 12

Act.Popup "Docking Station" ,5,"Computer Type", 0 + 32

Case 13

Act.Popup "All-in-One" ,5,"Computer Type", 0 + 32

Case 14

Act.Popup "Sub-Notebook" ,5,"Computer Type", 0 + 32

Case 15

Act.Popup "Space Saving" ,5,"Computer Type", 0 + 32

Case 16

Act.Popup "Lunch Box" ,5,"Computer Type", 0 + 32

Case 17

Act.Popup "Main System Chassis" ,5,"Computer Type", 0 + 32

Case 18

Act.Popup "Expansion Chassis" ,5,"Computer Type", 0 + 32

Case 19

Act.Popup "Sub-Chassis" ,5,"Computer Type", 0 + 32

Case 20

Act.Popup "Bus Expansion Chassis" ,5,"Computer Type", 0 + 32

Case 21

Act.Popup "Peripheral Chassis" ,5,"Computer Type", 0 + 32

Case 22

Act.Popup "Storage Chassis" ,5,"Computer Type", 0 + 32

Case 23

Act.Popup "Rack Mount Chassis" ,5,"Computer Type", 0 + 32

Case 24

Act.Popup "Sealed-Case PC" ,5,"Computer Type", 0 + 32

Case Else

Act.Popup "Unknown" ,5,"Computer Type", 0 + 32

End Select

Next

Next

Function DeskTop

Act.Popup "Desktop" ,5,"Computer Type", 0 + 32

End Function

Link to comment
Share on other sites

A twist on the others, that I find easier to read:

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Setup"
objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colChassis = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
For Each objChassis in colChassis
For Each strChassisType in objChassis.ChassisTypes
Select Case strChassisType
Case 1
strEntryName = "MACHINETYPE"
strValue = "Other"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 2
strEntryName = "MACHINETYPE"
strValue = "Unknown"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 3
strEntryName = "MACHINETYPE"
strValue = "Desktop"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 4
strEntryName = "MACHINETYPE"
strValue = "Low_Profile_Desktop"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 5
strEntryName = "MACHINETYPE"
strValue = "Pizza_Box"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 6
strEntryName = "MACHINETYPE"
strValue = "Mini_Tower"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 7
strEntryName = "MACHINETYPE"
strValue = "Tower"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 8
strEntryName = "MACHINETYPE"
strValue = "Portable"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 9
strEntryName = "MACHINETYPE"
strValue = "Laptop"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 10
strEntryName = "MACHINETYPE"
strValue = "Notebook"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 11
strEntryName = "MACHINETYPE"
strValue = "Handheld"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 12
strEntryName = "MACHINETYPE"
strValue = "Docking_Station"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 13
strEntryName = "MACHINETYPE"
strValue = "All-in-One"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 14
strEntryName = "MACHINETYPE"
strValue = "Sub-Notebook"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 15
strEntryName = "MACHINETYPE"
strValue = "Space_Saving"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 16
strEntryName = "MACHINETYPE"
strValue = "Lunch_Box"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 17
strEntryName = "MACHINETYPE"
strValue = "Main_System_Chassis"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 18
strEntryName = "MACHINETYPE"
strValue = "Expansion_Chassis"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 19
strEntryName = "MACHINETYPE"
strValue = "Sub-Chassis"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 20
strEntryName = "MACHINETYPE"
strValue = "Bus_Expansion_Chassis"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 21
strEntryName = "MACHINETYPE"
strValue = "Peripheral_Chassis"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 22
strEntryName = "MACHINETYPE"
strValue = "Storage_Chassis"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 23
strEntryName = "MACHINETYPE"
strValue = "Rack_Mount_Chassis"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case 24
strEntryName = "MACHINETYPE"
strValue = "Sealed-Case_PC"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
Case Else
strEntryName = "MACHINETYPE"
strValue = "Unknown"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
End Select
Next
Next

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...