Difference between revisions of "Identify Client Form Factor"
Line 3: | Line 3: | ||
It relies on a vbs script which queries WMI to identify the hardware chassis type then writes the returned value to wherever you specify in the Registry.<br> | It relies on a vbs script which queries WMI to identify the hardware chassis type then writes the returned value to wherever you specify in the Registry.<br> | ||
− | You will then need to use | + | You will then need to use [http://wpkg.org/Packages.xml#Check_conditions_.2F_check_type logical conditions] to determine if an application target at a specific platform (laptop or desktop for example) is installed. Remember that logical conditions are counter-intuitive, if you want to install an application on a specific platform you check for what your target platform '''isn't'''. <br> |
For example:<br> | For example:<br> | ||
<source lang="xml"> | <source lang="xml"> | ||
Line 10: | Line 10: | ||
<check type="logical" condition="or"> | <check type="logical" condition="or"> | ||
<check type="uninstall" condition="versionequalorgreater" path="SonicWALL SSL-VPN NetExtender" value="3.5.108" /> | <check type="uninstall" condition="versionequalorgreater" path="SonicWALL SSL-VPN NetExtender" value="3.5.108" /> | ||
− | <check type='registry' condition='exists' path="HKLM\Software\ | + | <check type='registry' condition='exists' path="HKLM\Software\xxxxx\wpkg\ChassisType" value="Desktop" /> |
− | <check type='registry' condition='exists' path="HKLM\Software\ | + | <check type='registry' condition='exists' path="HKLM\Software\xxxxx\wpkg\ChassisType" value="Other" /> |
− | <check type='registry' condition='exists' path="HKLM\Software\ | + | <check type='registry' condition='exists' path="HKLM\Software\xxxxx\wpkg\ChassisType" value="Unknown" /> |
</check> | </check> | ||
</source> | </source> |
Revision as of 01:42, 11 November 2009
The following package identifies the client form factor and writes an entry into the Registry which can subsequently be read by other application install packages.
It relies on a vbs script which queries WMI to identify the hardware chassis type then writes the returned value to wherever you specify in the Registry.
You will then need to use logical conditions to determine if an application target at a specific platform (laptop or desktop for example) is installed. Remember that logical conditions are counter-intuitive, if you want to install an application on a specific platform you check for what your target platform isn't.
For example:
<!-- The registry checks below mean this package will only run on a laptop as defined by chassistype package
Remember that if any of the check conditions returns true the package is _not_ installed -->
<check type="logical" condition="or">
<check type="uninstall" condition="versionequalorgreater" path="SonicWALL SSL-VPN NetExtender" value="3.5.108" />
<check type='registry' condition='exists' path="HKLM\Software\xxxxx\wpkg\ChassisType" value="Desktop" />
<check type='registry' condition='exists' path="HKLM\Software\xxxxx\wpkg\ChassisType" value="Other" />
<check type='registry' condition='exists' path="HKLM\Software\xxxxx\wpkg\ChassisType" value="Unknown" />
</check>
Of course be sure to modify the xml and vbs below to your needs.
<?xml version="1.0" encoding="UTF-8"?>
<packages>
<package
id='chassistype'
name='ChassisType'
revision='1'
priority='999'
execute='once'
reboot='false'>
<check type='registry' condition='exists' path="HKLM\Software\xxxxx\wpkg\ChassisType" />
<install cmd='%COMSPEC% /c cscript //B "%SOFTWARE%\system\identify_chassis_simple.vbs"' />
<upgrade cmd='%COMSPEC% /c cscript //B "%SOFTWARE%\system\identify_chassis_simple.vbs"' />
<remove cmd='REG DELETE HKLM\Software\xxxxx\wpkg\ /v ChassisType /f' />
</package>
</packages>
Now I have two different versions of the vbs script, the identify_chassis_simple.vbs script writes "desktop" or "laptop" for a number of different chassis type return codes. The identify_chassis.vbs script at the bottom has a lot more chassis types if you need that granularity in your application installs (I don't).
The most important fields to modify in the vbs below are strKeyPath and possibly strValueName to suite your environment and ensure it is the same as the checktype registry path.
Identify Chassis Simple
strComputer = "."
const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\xxxxx\wpkg"
strValueName = "ChassisType"
strChassisValue = ""
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\default:StdRegProv")
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
strChassisValue = "Other"
Case 2
strChassisValue = "Unknown"
Case 3
strChassisValue = "Desktop"
Case 4
strChassisValue = "Desktop"
Case 5
strChassisValue = "Desktop"
Case 6
strChassisValue = "Desktop"
Case 7
strChassisValue = "Desktop"
Case 8
strChassisValue = "Laptop"
Case 9
strChassisValue = "Laptop"
Case 10
strChassisValue = "Laptop"
Case 11
strChassisValue = "Handheld"
Case 12
strChassisValue = "Docking Station"
Case 13
strChassisValue = "Desktop"
Case 14
strChassisValue = "Laptop"
Case 15
strChassisValue = "Desktop"
Case 16
strChassisValue = "Desktop"
Case 17
strChassisValue = "Desktop"
Case 18
strChassisValue = "Expansion Chassis"
Case 19
strChassisValue = "Sub-Chassis"
Case 20
strChassisValue = "Bus Expansion Chassis"
Case 21
strChassisValue = "Peripheral Chassis"
Case 22
strChassisValue = "Storage Chassis"
Case 23
strChassisValue = "Rack Mount Chassis"
Case 24
strChassisValue = "Desktop"
Case Else
strChassisValue = "Unknown"
End Select
Next
Next
RegResult = objReg.SetStringValue(HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strChassisValue)
Identify Chassis Full
strComputer = "."
const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\xxxxx\wpkg"
strValueName = "ChassisType"
strChassisValue = ""
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\default:StdRegProv")
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
strChassisValue = "Other"
Case 2
strChassisValue = "Unknown"
Case 3
strChassisValue = "Desktop"
Case 4
strChassisValue = "Low Profile Desktop"
Case 5
strChassisValue = "Pizza Box"
Case 6
strChassisValue = "Mini Tower"
Case 7
strChassisValue = "Tower"
Case 8
strChassisValue = "Portable"
Case 9
strChassisValue = "Laptop"
Case 10
strChassisValue = "Notebook"
Case 11
strChassisValue = "Handheld"
Case 12
strChassisValue = "Docking Station"
Case 13
strChassisValue = "All-in-One"
Case 14
strChassisValue = "Sub-Notebook"
Case 15
strChassisValue = "Space Saving"
Case 16
strChassisValue = "Lunch Box"
Case 17
strChassisValue = "Main System Chassis"
Case 18
strChassisValue = "Expansion Chassis"
Case 19
strChassisValue = "Sub-Chassis"
Case 20
strChassisValue = "Bus Expansion Chassis"
Case 21
strChassisValue = "Peripheral Chassis"
Case 22
strChassisValue = "Storage Chassis"
Case 23
strChassisValue = "Rack Mount Chassis"
Case 24
strChassisValue = "Sealed-Case PC"
Case Else
strChassisValue = "Unknown"
End Select
Next
Next
RegResult = objReg.SetStringValue(HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strChassisValue)