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

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

  • Comments 11
  • Likes
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!

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Excellent info - very handy!

    FYI, for anyone else investigating this for any reason..

    I have come across machines that DO have more than one chassis type (Laptops on docking stations are Laptop/Notebook + Expansion Chassis)

    Hope this helps!

  • Slight variation on the topic: how does *Windows* determine whether the computer is a desktop or a laptop/mobile computer?  Many features (e.g. Windows 7 Location-Aware Printing) are only available on mobile computers, which is a shame because many desktops are also occasionally moved from place to place.  So what is the determining factor in the eyes of Windows? ... and can it be told otherwise?

    Thanks,

    Jacques.

  • Starting with Windows Vista there is a new Property available within the Win32_ComputerSystem class that can be used for this.

    The property is PCSystemType and a laptop should always return a value of '2'.

    I have already started using this method in scripts that will only be executed on Vista and above and it makes things much easier!

    Here is the MSDN link for the Win32_ComputerSystem class:

    msdn.microsoft.com/.../aa394102%28VS.85%29.aspx

    Happy scripting!

  • One reason (apparently) why this property is an array, is because of the docking station type. My laptop returns both 10 and 12, indicating that it's a notebook with a docking station.

  • @emptee Not all laptop computers report correctly. I have written about a function I wrote that uses multiple techniques to determine if a laptop or not. blogs.technet.com/.../hey-scripting-guy-weekend-scripter-how-can-i-use-wmi-to-detect-laptops.aspx

  • @JBensimon I am not certain how WIndows 7 determines if a laptop is present or not. But you are correct, that certain features are only available for laptops. It is possible the information comes from the bios, or even via WMI as mentioned here. I do not think overriding laptop / or not would be supported.

  • @Wayne_C thank you for sharing this with us. This is very useful information that I had overlooked.

  • @Ingmar yes, I have seen several systems that report multiple values for the chassis type. You are correct.

  • That 'Lunch Box' type (16) is hilarious.  Guess somebody at Microsoft wanted to have a little fun.

  • Hi All

    i would like to execute this script for an OU only, is this possible?

  • @ikeytiger - In Group Policy management you go to the GPO in question (that you have configured) and select it, then set the WMI Filtering filter on the right hand pane at the bottom.

    Whichever site, domain or OU that the GPO is linked will utilise the WMI filter when executing.

    Hope that helps.