Delen via


WMI Tags for Task Sequencer Logic

One of the things that I am often required to obtain for customers are certain WMI tags so that we can write task sequence IF statements and provide the build process with some logic. Gathering these WMI tags can be tricky, so we put together a VB Script to pull out the 10 most popular items and display them to the screen - we also copy the results to a file called sysinfo.txt. By running this file on the machines that will be built, we can ensure that we use the correct WMI entries for things like MANUFACTURER, MODEL and CHASIS.

The scipt (sysinfo.vbs) is listed below and is a variation on the script used by BDD to gather information at the start of the build process:

' Initialization
Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("Wscript.Shell")
Set reg = GetObject("winmgmts:root\default:StdRegProv")
Dim sOutput

On Error Resume Next

' Create the appropriate OS information
For each os in GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
   If Instr(1,os.caption,"XP") <> 0 then Call makefile("OS = XP")
   If Instr(1,os.caption,"2000") <> 0 then Call makefile("OS = WIN2000")
   If Instr(1,os.caption,"2003") <> 0 then Call makefile("OS = WIN2003")
   If Instr(1,os.caption,"NT") <> 0 then Call makefile("OS = NT4")
   If Instr(1,os.caption,"2000 Server") <> 0 then  Call makefile("OSTYPE = SERVER")
   If Instr(1,os.caption,"Advanced Server") <> 0 then  Call makefile("OSTYPE = ADVANCED")
   If Instr(1,os.caption,"Professional") <> 0 then  Call makefile("OSTYPE = PRO")
   If Instr(1,os.caption,"Standard") <> 0 then Call makefile("OSTYPE = STANDARD")
   If Instr(1,os.caption,"Enterprise") <> 0 then Call makefile("OSTYPE = ENTERPRISE")
   If Instr(1,os.caption,"Web") <> 0 then Call makefile("OSTYPE = WEB")
   If os.ServicePackMajorVersion <> "" then
      Call makefile("OSSP = " & os.ServicePackMajorVersion)
   Else
      Call makefile("OSSP = NONE")
   End if
Next

' Obtain the enclosure type
for each Enclosure in GetObject("winmgmts:").InstancesOf("Win32_SystemEnclosure")
   if join (Enclosure.Tag)<>"System Enclosure 1" then
      CaseType = Enclosure.ChassisTypes(0)
   end if
next
Select case CaseType
  Case "3", "4", "5", "6", "7", "15"
     Call makefile("CHASSIS = " & "DESKTOP")

  Case "8", "10", "12", "14", "18", "21"
     Call makefile("CHASSIS = " & "LAPTOP")

  Case "23"
     Call makefile("CHASSIS = " & "SERVER")

  Case ELSE
     Call makefile("CHASSIS = " & "OTHER")
End Select

' Since there is no good way to identify a Tablet PC except by using an API call (GetSystemMetrics),
' cheat and use a well-known registry location.
Err.Clear
ver = shell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Tablet PC\Ident")
If Err then
    ' Not a tablet
Else
    Call makefile("OSTYPE = TABLET")
End if

' Obtain the HAL that is being used
halID = shell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E966-E325-11CE-BFC1-08002BE10318}\0000\MatchingDeviceId")
halName = shell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E966-E325-11CE-BFC1-08002BE10318}\0000\DriverDesc")
'Wscript.Echo "HAL ID=" & halID
'Wscript.Echo "HAL Name=" & halName
Call makefile("HALID = " & halID)
Call makefile("HALNAME = " & halName)

' Obtain the manufacturer and model
For each os in GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")
   If Instr(1,os.Manufacturer," ") <> 0 then
      Manu=Left(os.Manufacturer,(instr(1,os.Manufacturer," "))-1)
   else
      Manu=os.manufacturer
   end if
   Call makefile("MANUFACTURER = "&manu)
   Call makefile("MODEL = "&os.model)
Next

' Get the CD/DVD information
x = 0
CD = false
DVD = false
For each os in GetObject("winmgmts:").InstancesOf("Win32_CDROMDrive")
   x = x + 1
   If Instr(1,UCASE(os.name),"RW") <> 0 then Call makefile("CDROM-RW")
   If Instr(1,UCASE(os.name),"DVD") <> 0 then
      DVD = true
   ElseIf instr(1,UCASE(os.name),"DV")<>0 then
      DVD = true
   ElseIf instr(1,UCASE(os.name),"CD")<>0 then
      CD = true
   End If
Next
If DVD then
   Call makefile("CDROM = DVD")
ElseIf CD then
   Call makefile("CDROM = CD")
Else
   Call makefile("CDROM = NONE")
End if

' Get the BIOS information
For each os in GetObject("winmgmts:").InstancesOf("Win32_BIOS")
   Call makefile("BIOS = "&os.SMBIOSBIOSVERSION)
Next

' Get the video information
For each os in GetObject("winmgmts:").InstancesOf("Win32_VideoController")
   Call makefile("VIDEO = "&os.name)
next

' Get the audio information
For each os in GetObject("winmgmts:").InstancesOf("Win32_SoundDevice")
   Call makefile("Audio = "&os.name)
Next

' Display output
shell.popup sOutput

'create a file called sysinfo.txt
call CreateFile

Sub Makefile (filename)
 filename = Trim(filename) ' Strip whitespace
 sOutput = sOutput & filename & vbcrlf
End sub

Sub CreateFile()
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set objTextFile = objFSO.OpenTextFile("sysinfo.txt", 2, True)
 objTextFile.WriteLine sOutput
 objTextFile.Close
End Sub

A simple alternative to this script - if you just want to find make and model information - is to follow the process identified by my MCS colleague Ben

1. Open a Command Prompt

2. Type WMIC

3. To determine the Make, type CSProduct Get Vendor

4. To determine the Model, type CSProduct Get Name

Ben also has an excellent article on how to use specific WMI information in rules to perform different tasks based on hardware types. You can find his blog entry here