Novell Home

How To Determine if a Computer is a Laptop or a Desktop Machine or Docking Station or ..?

Novell Cool Solutions: Feature
By Greg DeBrun

Rate This Page

Reader Rating  stars  from 10 ratings

Digg This - Slashdot This

Posted: 13 Jul 2005
 

This could be helpful for setting policies, pushing out certain applications, etc. I read a lot of information about different ways to tell if the computer was a laptop like search for a battery file or power setting, but could never get a good test. The solution is my VBS script and accessing the Windows Management Instrumentation (WMI).

Windows Management Instrumentation (WMI) is the Microsoft implementation of Web-Based Enterprise Management (WBEM), which is an industry initiative to develop a standard technology for accessing management information in an enterprise environment. WMI uses the Common Information Model (CIM) industry standard to represent systems, applications, networks, devices, and other managed components. You can use WMI to automate administrative tasks in an enterprise environment.

Well, enough of the boring stuff. Here is the solution.

Solution

I put together this VBS script to assist with this problem. It turns out there's a WMI class called Win32_SystemEnclosure, and there is a ChassisTypes property which can tell you whether a computer is a laptop, a desktop, or some other kind of computer.

The Win32_SystemEnclosure WMI class represents the properties that are associated with a physical system enclosure. There are roughly 24 defined ChassisTypes. I'm not sure what some of them really are, but in our environment of around 1500 computers, we had about 5 different types.

My script will query the computer and return the ChassisTypes Value. It then looks up the value meaning and writes the entry to a key I've defined in the registry. Once the key is written, you can create your ZENworks policies and/or apps to look for this value in the registry. It's also a nice way to get a breakdown of the types of computers you have on the network.

Here is the script. Copy it to Notepad and save it as regpctype.vbs. Then create an application and force run it once on each computer to create the registry key.

Good luck.

(For some reason if you can't copy the code, let me know and I can send the file.)

Example

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\DOC's Computer Type"
objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath

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
        strEntryName = "PCTYPE"
        strValue = "Other"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue           
           Case 2
        strEntryName = "PCTYPE"
        strValue = "Unknown"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 3
        strEntryName = "PCTYPE"
        strValue = "Desktop"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 4
        strEntryName = "PCTYPE"
        strValue = "Low Profile Desktop"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 5
        strEntryName = "PCTYPE"
        strValue = "Pizza Box"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 6
        strEntryName = "PCTYPE"
        strValue = "Mini Tower"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 7
        strEntryName = "PCTYPE"
        strValue = "Tower"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 8
        strEntryName = "PCTYPE"
        strValue = "Portable"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 9
        strEntryName = "PCTYPE"
        strValue = "Laptop"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 10
        strEntryName = "PCTYPE"
        strValue = "Notebook"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 11
        strEntryName = "PCTYPE"
        strValue = "Handheld"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 12
        strEntryName = "PCTYPE"
            objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 14
        strEntryName = "PCTYPE"
        strValue = "Sub-Notebook"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 15
        strEntryName = "PCTYPE"
        strValue = "Space Saving"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 16
        strEntryName = "PCTYPE"
        strValue = "Lunch Box"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 17
        strEntryName = "PCTYPE"
        strValue = "Main System Chassis"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 18
        strEntryName = "PCTYPE"
        strValue = "Expansion Chassis"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 19
        strEntryName = "PCTYPE"
        strValue = "Sub-Chassis"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 20
        strEntryName = "PCTYPE"
        strValue = "Bus Expansion Chassis"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 21
        strEntryName = "PCTYPE"
        strValue = "Peripheral Chassis"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 22
        strEntryName = "PCTYPE"
        strValue = "Storage Chassis"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 23
        strEntryName = "PCTYPE"
        strValue = "Rack Mount Chassis"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case 24
        strEntryName = "PCTYPE"
        strValue = "Sealed-Case PC"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           Case Else
        strEntryName = "PCTYPE"
        strValue = "Unknown"
        objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
           End Select
   Next
Next

If you have any questions you may contact Greg at gdebrun@idph.state.il.us

Reader Comments

  • Good job!
  • Needs comments. Otherwise I would give it a 5
  • I would have given this a 5 if you had commented your code.
  • Quite helpful, though there is a lot of redundant code. strEntryName = "PCTYPE" objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue Could have been done after the select statement instead of 24 times.
  • excellent idea, great cool tool, give the guy a prize!
  • Looks like there's not a string entry written for type/case 12, MSDN reports type 12 = "Docking Station"
  • Fantastic. Now that I can distribute apps only to laptops, my job just got a little bit easier. Well done, and thanks
  • Little sloppy, but a great idea. As others have mentioned you should clean-up much of the script and provide comments/sources for said functions. For example, when fixing/adding the missing ChassisTypes values... Platform SDK: Windows Management Instrumentation Win32_SystemEnclosure http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_systemenclosure.asp

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

Novell® Making IT Work As One

© 2009 Novell, Inc. All Rights Reserved.