Friday 2 March 2018

VB Script: Script to identify the mahince is Desktop or Laptop or Others.

There will be scenarios we face sometimes like need to identify the machine is desktop or laptop and proceed to install the software accordingly.
Here is the script to verify the system is a Desktop.
Solution
   Dim strNameSpace
    Dim oEnclosures, objChassis,strChassisType
    strNameSpace = "\root\cimv2"
    Set oEnclosures = GetObject("winmgmts:").InstancesOf("Win32_SystemEnclosure")
    ForEach objChassisIn oEnclosures
    ForEach strChassisTypeIn objChassis.ChassisTypes       
    SelectCase strChassisType         
            Case"3"    ' Desktop         
              Desktop = True      
            Case"4"    ' Low Profile Desktop         
              Desktop = True      
            Case"5"    ' Pizza Box         
              Desktop = True    
            Case"6"    ' Mini Tower         
              Desktop = True
            Case"7"    ' Tower          
              Desktop = True
            Case"15"    ' Space-Saving         
              Desktop = True  
            Case"16"    ' Lunch Box       
              Desktop = True
            CaseElse   
              Desktop = False
        EndSelect  
    Next
    Next
    
    If Desktop = TrueThen
        MsgBox"The machine is desktop"
    Else
        MsgBox"The machine is not a desktop"
    EndIf
    
    Set oEnclosures = Nothing    
    Set strChassisType = Nothing
    Set objChassis = Nothing


Note: Modify the script based on your needs, suppose if you want to check the machine is a laptop or others.
'############################################################       
'ChassisTypes Value Meaning 
'1 Other 
'2 Unknown 
'3 Desktop 
'4 Low Profile Desktop 
'5 Pizza Box  
'6 Mini Tower 
'7 Tower 
'8 Portable 
'9 Laptop 
'10 Notebook 
'11 Hand Held 
'12 Docking Station 
'13 All in One 
'14 Sub Notebook 
'15 Space-Saving 
'16 Lunch Box  
'17 Main System Chassis 
'18 Expansion Chassis 
'19 SubChassis 
'20 Bus Expansion Chassis 
'21 Peripheral Chassis 
'22 Storage Chassis 
'23 Rack Mount Chassis 
'24 Sealed-Case PC 

'Thus, the following Chassis Types are typical to:
'laptops: 8 , 9, 10, 11, 12, 14, 18, 21
'desktops: 3, 4, 5, 6, 7, 15, 16
'servers: 17,23
'#########################################################

No comments:

Post a Comment