September 21st, 2004

How Can I Determine if a Computer is a Laptop or a Desktop Machine?

Hey, Scripting Guy! Question

Hey, Scripting Guy! Is there any way to use WMI to determine whether a computer is a laptop or a desktop machine?

— CB

SpacerHey, Scripting Guy! AnswerScript Center

Hey, CB. You bet there is, although if you didn’t know that we have no idea how you’d figure it out on your own. It turns out there’s a goofy little WMI class called Win32_SystemEnclosure, and the ChassisTypes property can tell you whether a computer is a laptop, a desktop, or some other kind of top. Uh, type. Here a script that tells you what type of chassis you’re dealing with:

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 strChassisType in objChassis.ChassisTypes
        Wscript.Echo strChassisType
    Next
Next

Ok, so the preceding script only kind of tells you what type of chassis you’re dealing with. The ChassisType property actually returns a number, which means when we run the script on the computer sitting here in front of us we get back a 10. What’s a 10? According to the WMI SDK, that means this is a notebook computer. And guess what? It is!

But you don’t have to refer to the SDK each time you check the chassis type. Here’s an expanded version of the script that uses a Select Case statement to convert these integers to something a bit more meaningful:

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 strChassisType in objChassis.ChassisTypes
        Select Case strChassisType
            Case 1
                Wscript.Echo "Other"
            Case 2
                Wscript.Echo "Unknown"
            Case 3
                Wscript.Echo "Desktop"
            Case 4
                Wscript.Echo "Low Profile Desktop"
            Case 5
                Wscript.Echo "Pizza Box"
            Case 6
                Wscript.Echo "Mini Tower"
            Case 7
                Wscript.Echo "Tower"
            Case 8
                Wscript.Echo "Portable"
            Case 9
                Wscript.Echo "Laptop"
            Case 10
                Wscript.Echo "Notebook"
            Case 11
                Wscript.Echo "Handheld"
            Case 12
                Wscript.Echo "Docking Station"
            Case 13
                Wscript.Echo "All-in-One"
            Case 14
                Wscript.Echo "Sub-Notebook"
            Case 15
                Wscript.Echo "Space Saving"
            Case 16
                Wscript.Echo "Lunch Box"
            Case 17
                Wscript.Echo "Main System Chassis"
            Case 18
                Wscript.Echo "Expansion Chassis"
            Case 19
                Wscript.Echo "Sub-Chassis"
            Case 20
                Wscript.Echo "Bus Expansion Chassis"
            Case 21
                Wscript.Echo "Peripheral Chassis"
            Case 22
                Wscript.Echo "Storage Chassis"
            Case 23
                Wscript.Echo "Rack Mount Chassis"
            Case 24
                Wscript.Echo "Sealed-Case PC"
            Case Else
                Wscript.Echo "Unknown"
            End Select
    Next
Next

Before you ask, no, we don’t really know what most of these chassis types are, nor do we know what the difference is between a portable, a laptop, and a notebook. We also don’t know why the ChassisTypes property is stored as an array. Does that mean a computer could have more than one chassis type? Don’t ask us; we don’t know. But give us a break: after all, we’re the Microsoft Scripting Guys, not the Microsoft Hardware Guys!

Author

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • Justin Davis

    Very old post, but still relevant. I thought I’d add with SMBIOS 3.0 three new Chassis Types.

    30 – Tablet
    31 – Convertible
    32 – Detachable