Jump to content

Script to determine if it's a desktop or laptop


Recommended Posts

Hi

I found the following script online to determine what type of hardware I have. I would like help from someone if possible. What I would like to have happen is if it's a laptop kick of an installation from an msi from within the unattend.xml from within the first login commands section.

can some take a look at the script and tell me the what I have to add to make this happen.



Option Explicit
Dim strComputer, strChassis
Dim objWMIService, objChassis, colChassis, objItem
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colChassis = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure",,16)
For Each objChassis in colChassis
For Each objItem in objChassis.ChassisTypes
Select Case objItem
Case 1 strChassis = "Maybe Virtual Machine"
Case 2 strChassis = "??"
Case 3 strChassis = "Desktop"
Case 4 strChassis = "Thin Desktop"
Case 5 strChassis = "Pizza Box"
Case 6 strChassis = "Mini Tower"
Case 7 strChassis = "Full Tower"
Case 8 strChassis = "Portable"
Case 9 strChassis = "Laptop"
Case 10 strChassis = "Notebook"
Case 11 strChassis = "Hand Held"
Case 12 strChassis = "Docking Station"
Case 13 strChassis = "All in One"
Case 14 strChassis = "Sub Notebook"
Case 15 strChassis = "Space-Saving"
Case 16 strChassis = "Lunch Box"
Case 17 strChassis = "Main System Chassis"
Case 18 strChassis = "Lunch Box"
Case 19 strChassis = "SubChassis"
Case 20 strChassis = "Bus Expansion Chassis"
Case 21 strChassis = "Peripheral Chassis"
Case 22 strChassis = "Storage Chassis"
Case 23 strChassis = "Rack Mount Unit"
Case 24 strChassis = "Sealed-Case PC"

End Select
Next
Next
WScript.Echo "Computer chassis type: " & strChassis
'WScript.Echo strComputer & "'s chassis type: " & strChassis

WScript.Quit

' End of WMI VBScript - Chassis type

EDIT: This is in reference to this thread:

Edited by Tripredacus
added reference link
Link to comment
Share on other sites


Have the unattend execute your script, and have the script do something like this:

Option Explicit
Dim strComputer, strChassis
Dim objWMIService, objChassis, objItem, objShellApp
Dim execOutput, isRunning, colChassis

RunMeWithCscript()

WScript.StdOut.Write vbCrLf & "Started at: " & Now

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colChassis = objWMIService.ExecQuery( _
"SELECT * FROM Win32_SystemEnclosure",,48)

For Each objChassis in colChassis
strChassis = Join(objChassis.ChassisTypes, ",")
If strChassis = 9 Then
Set objShellApp = CreateObject("WScript.Shell")
Set isRunning = objShellApp.Exec("msiexec /i <drive:\path\to\file>.msi")

Do While isRunning.Status = 0
WScript.Sleep 100
execOutput = isRunning.StdOut.ReadAll
Loop
Set isRunning = Nothing
Else
'// It's a UFPO - Unknown Floating Point Operator!!! ALIENS!!!
End If
Next

WScript.StdOut.Write vbCrLf & "strChassis: " & strChassis
WScript.StdOut.Write vbCrLf & "Finished at: " & Now



Sub RunMeWithCScript()
Dim ScriptEngine, engineFolder, Args, arg, scriptName, argString, scriptCommand

ScriptEngine = UCase(Mid(WScript.FullName, InstrRev(WScript.FullName, "\") + 1))
engineFolder = Left(WScript.FullName, InstrRev(WScript.FullName, "\"))
argString = ""
'WScript.Echo ScriptEngine

If ScriptEngine = "WSCRIPT.EXE" Then
Dim Shell
Set Shell = CreateObject("WScript.Shell")
Set Args = WScript.Arguments

For Each arg in Args 'loop though argument array as a collection to rebuild argument string
If InStr(arg, " ") > 0 Then arg = """" & arg & """" 'If the argument contains a space wrap it in double quotes
argString = argString & " " & Arg
Next

'Create a persistent command prompt for the cscript output window and call the script with its original arguments
scriptCommand = "cmd.exe /k " & engineFolder & "cscript.exe """ & WScript.ScriptFullName & """" & argString

Shell.Run scriptCommand, , False
WScript.Quit
Else
Exit Sub 'Already Running with Cscript Exit this Subroutine
End If
End Sub

Link to comment
Share on other sites

Here is the snippet from MDT 2010 that does that...

' Get the SMBIOS asset tag from the Win32_SystemEnclosure class

Set objResults = objWMI.InstancesOf("Win32_SystemEnclosure")
bIsLaptop = false
bIsDesktop = false
bIsServer = false
For each objInstance in objResults

If objInstance.ChassisTypes(0) = 12 or objInstance.ChassisTypes(0) = 21 then
' Ignore docking stations
Else

If not IsNull(objInstance.SMBIOSAssetTag) then
sAssetTag = Trim(objInstance.SMBIOSAssetTag)
End if
Select Case objInstance.ChassisTypes(0)
Case "8", "9", "10", "11", "12", "14", "18", "21"
bIsLaptop = true
Case "3", "4", "5", "6", "7", "15", "16"
bIsDesktop = true
Case "23"
bIsServer = true
Case Else
' Do nothing
End Select

End if

Next

/ Johan

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...