Using the VBS implementation to determine whether the computer is a notebook or a desktop code _vbs

Source: Internet
Author: User
Tags case statement
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.