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