作者:宋羽翔-ben | 来源:互联网 | 2024-12-17 17:00
通过WMI(Windows Management Instrumentation)提供的Win32_SystemEnclosure类,我们可以轻松获取当前计算机的物理特性信息,包括其外壳类型(Chassis Type)。这有助于确定设备是台式机、笔记本电脑还是其他形式的计算设备。
下面是一个简单的Vbscript示例,用于查询并显示计算机的外壳类型:
```vb
strComputer = "localhost"
Set objWMIService = GetObject("winmgmts:\" & 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 "其他"
Case 2: Wscript.Echo "未知"
Case 3: Wscript.Echo "台式机"
Case 4: Wscript.Echo "低矮台式机"
Case 5: Wscript.Echo "披萨盒型"
Case 6: Wscript.Echo "迷你塔式机"
Case 7: Wscript.Echo "塔式机"
Case 8: Wscript.Echo "便携式"
Case 9: Wscript.Echo "笔记本电脑"
Case 10: Wscript.Echo "笔记本型"
Case 11: Wscript.Echo "手持设备"
Case 12: Wscript.Echo "对接站"
Case 13: Wscript.Echo "一体机"
Case 14: Wscript.Echo "子笔记本型"
Case 15: Wscript.Echo "节省空间型"
Case 16: Wscript.Echo "午餐盒型"
Case 17: Wscript.Echo "主系统外壳"
Case 18: Wscript.Echo "扩展外壳"
Case 19: Wscript.Echo "子外壳"
Case 20: Wscript.Echo "总线扩展外壳"
Case 21: Wscript.Echo "外围设备外壳"
Case 22: Wscript.Echo "存储外壳"
Case 23: Wscript.Echo "机架安装外壳"
Case 24: Wscript.Echo "密封外壳PC"
Case Else: Wscript.Echo "未知类型"
End Select
Next
Next
```
此脚本会输出一个或多个与您的计算机相关的外壳类型名称。例如,如果您的计算机是一台笔记本电脑,脚本可能会输出“10”对应的“笔记本型”。值得注意的是,虽然通常一台计算机只有一个外壳类型,但在某些特殊情况下,如多模块设计的系统中,也可能存在多个类型。