From time to time, it can be helpful to determine if your code is running on a laptop computer rather than a desktop PC or server. The following code, when supplied the name of a PC on the network to which the user has administrator rights, will use Windows Management Instrumentation to determine if the PC is a “portable” chassis type or not. If it’s a portable PC, the code returns true. Otherwise, false.
'
' This function will use WMI to attempt to identify if
' the given machine is a laptop/portable/notebook PC or
' not. It returns "true" if a laptop, "false" if not.
'
' It will return false if the machine is offline.
'
'
function isLaptop(pcName)
on error resume next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & pcname & "\root\cimv2")
Set colChassis = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
itsALaptop = false
For Each objChassis in colChassis
For Each strChassisType in objChassis.ChassisTypes
select case strChassisType
case 8, 9, 10, 14:
itsALaptop = true
end select
Next
Next
on error goto 0
isLaptop = itsALaptop
end function
