Jump to content

Install based on Desktop or Laptop


Recommended Posts

I ran into a problem where I wanted to install Sierra Wireless AirCard software and the Cisco VPN Client on only computer that were portable (makes sense right?). So I came up with a fairly simple script to determine the computer type and then take appropriate action. I made switchless silent installers for the software to make things easy on myself. As I usually do, I made this into a subroutine for easy integration into your own script. I hope some of you find this to be of use.

Dim ws
Set ws = WScript.CreateObject("WScript.Shell")

Sub InstallVPN
Dim strComputer, objWMIService, colChassis, objChassis, strChassisType
strComputer = "."
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 'Other
              Case 2 'Unknown
              Case 3 'Desktop
              Case 4 'Low Profile Desktop
              Case 5 'Pizza Box
              Case 6 'Mini Tower
              Case 7 'Tower
              Case 8 'Portable
                ws.Run("\\MyDomain.Local\DfsRoot\Software\AirCard.exe")
                ws.Run("\\MyDomain.Local\DfsRoot\Software\CiscoVPN.exe")
            Case 9 'Laptop
                ws.Run("\\MyDomain.Local\DfsRoot\Software\AirCard.exe")
                ws.Run("\\MyDomain.Local\DfsRoot\Software\CiscoVPN.exe")
            Case 10 'Notebook
                ws.Run("\\MyDomain.Local\DfsRoot\Software\AirCard.exe")
                ws.Run("\\MyDomain.Local\DfsRoot\Software\CiscoVPN.exe")
            Case 11 'Handheld
                ws.Run("\\MyDomain.Local\DfsRoot\Software\AirCard.exe")
                ws.Run("\\MyDomain.Local\DfsRoot\Software\CiscoVPN.exe")
            Case 12 'Docking Station
                ws.Run("\\MyDomain.Local\DfsRoot\Software\AirCard.exe")
                ws.Run("\\MyDomain.Local\DfsRoot\Software\CiscoVPN.exe")
            Case 13 'All-in-One
             Case 14 'Sub-Notebook
                ws.Run("\\MyDomain.Local\DfsRoot\Software\AirCard.exe")
                ws.Run("\\MyDomain.Local\DfsRoot\Software\CiscoVPN.exe")
            Case 15 'Space Saving
              Case 16 'Lunch Box
            Case 17 'Main System Chassis
            Case 18 'Expansion Chassis
            Case 19 'Sub-Chassis
            Case 20 'Bus Expansion Chassis
            Case 21 'Peripheral Chassis
            Case 22 'Storage Chassis
            Case 23 'Rack Mount Chassis
            Case 24 'Sealed-Case PC
            Case Else 'Unknown
            End Select
    Next
Next
End Sub

InstallVPN

Please note that I have no clue at all what some of these chassis types are. They're what I found on Microsoft's WMI SDK web site. Also this script is adapted from a RIS install routine, but you can obviously change the path to suit a local source.

Edited by RogueSpear
Link to comment
Share on other sites


I could not get your script to work on my computer, so I re wrote it. It only confirms what type of computer now.

Dim Act : Set Act = WScript.CreateObject("WScript.Shell")

Dim strComputer, objWMIService, colChassis, objChassis, strChassisType, CType

  strComputer = "."

  '''' Popup Box

  Function MBox

  Act.Popup "Confirm Type" & vbCrLf & CType, 5, "Confirm",0 + 32

  End Function

  '''' Collect the computer type

  Function CompType

  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

    CType = strChassisType

    Next

  Next

  CompTypeAction

  End Function

  '''' Runs Check to see what type is true

  Function CompTypeAction

  If CType <> 0 Then

    If CType = 1 Then 'Other

    CType = "Other"

    MBox

      CType = strChassisType

    End If

    If CType = 2 Then 'Unknown

    CType = "Unknown"

    MBox

      CType = strChassisType

    End If

    If CType = 3 Then 'Desktop

    CType = "Desktop"

    MBox

      CType = strChassisType

    End If

    If CType = 4 Then 'Low Profile Desktop

    CType = "Low Profile Desktop"

    MBox

      CType = strChassisType

    End If

    If CType = 5 Then 'Pizza Box

    CType = "Pizza Box"

    MBox

      CType = strChassisType

    End If

    If CType = 6 Then 'Mini Tower

    CType = "Mini Tower"

    MBox

      CType = strChassisType

    End If

    If CType = 7 Then 'Tower

    CType = "Tower"

    MBox

      CType = strChassisType

    End If

    If CType = 8 Then 'Portable

    CType = "Portable"

    MBox

      CType = strChassisType

    End If

    If CType = 9 Then 'Laptop

    CType = "Laptop"

    MBox

      CType = strChassisType

    End If

    If CType = 10 Then 'Notebook

    CType = "Notebook"

    MBox

      CType = strChassisType

    End If

    If CType = 11 Then 'Handheld

    CType = "Portable"

    MBox

      CType = strChassisType

    End If

    If CType = 12 Then 'Docking Station

    CType = "Docking Station"

    MBox

      CType = strChassisType

    End If

    If CType = 13 Then 'All-in-One

    CType = "Portable"

    MBox

      CType = strChassisType

    End If

    If CType = 14 Then 'Sub-Notebook

    CType = "Sub-Notebook"

    MBox

      CType = strChassisType

    End If

    If CType = 15 Then 'Space Saving

    CType = "Space Saving"

    MBox

      CType = strChassisType

    End If

    If CType = 16 Then 'Lunch Box

    CType = "Lunch Box"

    MBox

      CType = strChassisType

    End If

    If CType = 17 Then 'Main System Chassis

    CType = "Main System Chassis"

    MBox

      CType = strChassisType

    End If

    If CType = 18 Then 'Expansion Chassis

    CType = "Expansion Chassis"

    MBox

      CType = strChassisType

    End If

    If CType = 19 Then 'Sub-Chassis

    CType = "Sub-Chassis"

    MBox

      CType = strChassisType

    End If

    If CType = 20 Then 'Bus Expansion Chassis

    CType = "Portable"

    MBox

      CType = strChassisType

    End If

    If CType = 21 Then 'Peripheral Chassis

    CType = "Peripheral Chassis"

    MBox

      CType = strChassisType

    End If

    If CType = 22 Then 'Storage Chassis

    CType = "Storage Chassis"

    MBox

      CType = strChassisType

    End If

    If CType = 23 Then 'Rack Mount Chassis

    CType = "Rack Mount Chassis"

    MBox

      CType = strChassisType

    End If

    If CType = 24 Then 'Sealed-Case PC

    CType = "Sealed-Case PC"

    MBox

      CType = strChassisType

    End If

    Else

    Act.Popup "Error Unkown Computer Type", 5, "Error", 0 + 32

      Exit Function

    End If

  End Function

  CompType

Link to comment
Share on other sites

So, I will go out on a limb and assume that you want to install the Sierra and Cisco software on a notebook without regard to whether or not the wireless card is installed. Cuz if you only want to install software with corresponding hardware, then it would be better to test for the hardware existance rather than system enclosure type.

Dim objWMIService, colItems

Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter",,48)
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
Next

So test for Name = Your Sierra Wireless card and if true, install the software.

Link to comment
Share on other sites

Yes I do want to install the software no matter what. We have a fleet of notebook computers which outnumbers the AirCards. But they all need to be outfitted to run the AirCards. I did some major tweaking to the AirCard msi file - like removing the Network Access Monitor and it runs so much smoother than the stock install. It's really working out nice.

Link to comment
Share on other sites

For you the PnPBased would be better than PCType...

No, actually PnP would not be better in this circumstance. For this particular client, if the computer is a laptop then it should have the AirCard and VPN client installed. If I went to a PnP based routine here it would only complicate matters. There are indeed times when the only thing you want to determine is the formfactor of the unit.

Link to comment
Share on other sites

Ah, sorry, now I see what you mean. Here is the code I am using in my environment:

'PC type based actions
'Martin Zugec
'29.6.2005

strComputer = "."
Set objShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set arrayChassis = objWMIService.ExecQuery _
   ("Select * from Win32_SystemEnclosure")
Set objFSO = CreateObject("Scripting.FileSystemObject")    
   
For Each objChassis in arrayChassis
   For  Each strChassisType in objChassis.ChassisTypes
       Select Case strChassisType
           'Case 3 - Desktop
           Case 8 ' Notebooky
           ' Nastavenie klavesnice na ENG ako default
           strSwitchKeyboardRegFirst = "HKEY_USERS\.DEFAULT\Keyboard Layout\Preload\1"
           strSwitchKeyboardRegSecond = "HKEY_USERS\.DEFAULT\Keyboard Layout\Preload\2"
           objShell.RegWrite strSwitchKeyboardRegFirst, "00000409", "REG_SZ"
           objShell.RegWrite strSwitchKeyboardRegSecond, "00000405", "REG_SZ"
       End Select
   Next
Next

Right now I am using three different codes - this one is based on pc type (desktop, notebook etc.), second is based on computer model (gx270, gx280 etc.) and the last one (my favourite :)) is based on PnP identifiers...

Link to comment
Share on other sites

I'm currently working on using PnP identifiers for the purpose of installing drivers and applications that are for the proprietary keys on specific notebooks. In one environment, there are four different models of HP-Compaq laptops and each one has it's own "One Touch" keys :realmad: Not too mention the couple of Gateway models they have as well. Makes things a pain in the rear for sure.

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...