ChassisTypes 属性可以告诉您,您使用的是笔记本电脑、台式计算机还是其他类型的计算机。哦,输入。以下脚本可以让您知道您使用的是哪种类型的计算机:
复制代码 代码如下:
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
好吧,以上脚本只是在一定程度上让您知道您使用的是哪种类型的计算机。实际上,ChassisType 属性返回的是一个数字,这就是说当我们在面前的计算机上运行这个脚本时,我们将得到 10。那么,什么是 10 呢?根据WMI SDK,它指的是笔记本计算机。猜一猜会发生什么呢?没错!
但您并不必每次检查计算机类型时都参考 SDK。以下经过扩展的脚本使用一个 Select Case 语句,它可将这些整数转换为更有意义的内容:
复制代码 代码如下:
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
在您提问以前,不,我们并不知道这些大多数计算机类型是什么,也不知道便携式计算机、膝上型计算机以及笔记本计算机之间有什么区别。我们也不知道 ChassisTypes 属性为什么存储为数组。那是否意味着一台计算机可以有多种计算机类型?不要问我们,我们也不知道。让我们喘口气吧:毕竟我们只是 Microsoft Scripting Guy,可不是 Microsoft Hardware Guy
复制代码 代码如下:
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
好吧,以上脚本只是在一定程度上让您知道您使用的是哪种类型的计算机。实际上,ChassisType 属性返回的是一个数字,这就是说当我们在面前的计算机上运行这个脚本时,我们将得到 10。那么,什么是 10 呢?根据WMI SDK,它指的是笔记本计算机。猜一猜会发生什么呢?没错!
但您并不必每次检查计算机类型时都参考 SDK。以下经过扩展的脚本使用一个 Select Case 语句,它可将这些整数转换为更有意义的内容:
复制代码 代码如下:
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
在您提问以前,不,我们并不知道这些大多数计算机类型是什么,也不知道便携式计算机、膝上型计算机以及笔记本计算机之间有什么区别。我们也不知道 ChassisTypes 属性为什么存储为数组。那是否意味着一台计算机可以有多种计算机类型?不要问我们,我们也不知道。让我们喘口气吧:毕竟我们只是 Microsoft Scripting Guy,可不是 Microsoft Hardware Guy