The Chassistypes property can tell you whether you are using a portable computer, a desktop computer, or another type of computer. Oh, input. The following script lets you know what kind of computer you are using:
Copy Code code as follows:
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
Well, the above script just lets you know, to some extent, which type of computer you're using. In fact, the Chassistype property returns a number, which means that when we run this script on the computer before us, we get 10. So, what is 10? According to the WMI SDK, it refers to a notebook computer. Guess what's going to happen? That's right!
However, you do not have to refer to the SDK each time you check your computer type. The following extended script uses a Select Case statement that converts these integers to more meaningful content:
Copy Code code as follows:
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 questions, no, we don't know what these most computer types are, or what the difference is between laptops, laptops, and laptop computers. And we don't know why the Chassistypes property stores an array. Does that mean that a computer can have multiple computer types? Don't ask us, we don't know. Let's take a breather: After all, we're just Microsoft Scripting Guy, not Microsoft hardware guy.