System Enclosure

 

 

' COMMENT: <determines the type of enclosure of a computer>
' uses win32_systemEnclosure wmi Class
' tells make, model, and type of pc
' chasis type is returned as an array, so use an embedded for next loop
'==========================================================================

Option Explicit
'On Error Resume Next
dim strComputer
dim wmiNS
dim wmiQuery
dim objWMIService
dim colItems
dim objItem, chastype ' chastype holds the instance of chassisType
Dim arChasType ' array of chassis types from SDK
Dim ctype ' number contained in element(0) of chassis array

strComputer = "."
wmiNS = "\root\cimv2"
wmiQuery = "Select * from win32_systemenclosure"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)
Set colItems = objWMIService.ExecQuery(wmiQuery)

For Each objItem in colItems
Wscript.Echo "Manufacturer: " & objItem.Manufacturer
Wscript.Echo "Model: " & objItem.Model
Wscript.Echo "SerialNumber: " & objItem.SerialNumber
'There are two ways of obtaining the chassistype from the array. First
'is to use a for each to walk through the array as seen below.
'the second is to simply use the first element (0) in this case.
' For Each chastype In objItem.ChassisTypes
' ctype = chastype
' next
ctype = objItem.ChassisTypes(0)
Next

WScript.Echo FunChasType(ctype)

Function FunChasType(ctype)
arChasType = Array("Other","Unknown","Desktop","Low Profile Desktop","Pizza Box", "Mini Tower","Tower","Portable","Laptop","Notebook" _
,"Hand Held", "Docking Station","All in One","Sub Notebook","Space-Saving","Lunch Box ","Main System Chassis","Expansion Chassis" _
,"SubChassis","Bus Expansion Chassis","Peripheral Chassis","Storage Chassis","Rack Mount Chassis","Sealed-Case PC")
FunChasType = arChasType(ctype)
End Function