The chassistypes attribute tells you whether you are using a laptop, a desktop computer, or another type of computer. Oh, input. The following script will show you which type of computer you are using:
CopyCode The Code is as follows: strcomputer = "."
Set ob1_miservice = GetObject ("winmgmts :"_
& "{Impersonationlevel = impersonate }! \ "& Strcomputer &" \ Root \ cimv2 ")
Set colchassis = obw.miservice. execquery _
("Select * From win32_systemenclosure ")
For each objchassis in colchassis
For each strchassistype in objchassis. chassistypes
Wscript. Echo strchassistype
Next
Next
All right, the above scripts only let you know to some extent what type of computer you are using. In fact, the chassistype property returns a number, which means that when we run this script on the computer in front of us, we will get 10. So what is 10? According to the wmi sdk, it refers to a laptop. Guess what will happen? That's right!
However, you do not need to refer to the SDK every time you check the computer type. The following expanded script uses a select case statement that converts these integers into more meaningful content:
Copy code The Code is as follows: strcomputer = "."
Set ob1_miservice = GetObject ("winmgmts :"_
& "{Impersonationlevel = impersonate }! \ "& Strcomputer &" \ Root \ cimv2 ")
Set colchassis = obw.miservice. 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 the majority of these computers are, or what are the differences between portable computers, laptop computers, and laptops. We do not know why the chassistypes attribute is stored as an array. Does that mean that a computer can have multiple types of computers? Don't ask us. We don't know either. Let's take a breath: after all, we are only Microsoft scripting guy, not Microsoft hardware guy.