Page 1 of 1 1
Topic Options
#76800 - 2003-09-23 02:33 AM How to Determine System Type - ie Laptop
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Here is a script to attempt to determine the Manufacturer/System Chassis Type/and Serial Number

Most Admins seem to want to know how many systems are Laptops. This code should work well for recent systems. Older systems may not return data correctly.

Requires WMI
Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0 SP4 and later.
Server: Included in Windows Server 2003, Windows 2000 Server, Windows NT Server 4.0 SP4 and later.

This is based on the discussion from this posting.
http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=2;t=004588

The WMIQuery UDF is a modified version of the one from Radimus. This version is from Lonkero.
The main script idea is from Kent.






DIM $Set1, $Set2, $CaseType, $SystemType,$SerialNumb,$Mfg
$Set1=SetOption('Explicit','ON')
$Set2=SetOption('NoVarsInStrings','ON')

$CaseType=WMIQuery('ChassisTypes','Win32_SystemEnclosure')[0]
$SerialNumb=WMIQuery('SerialNumber','Win32_SystemEnclosure')[0]
$Mfg=WMIQuery('Manufacturer','Win32_SystemEnclosure')[0]

SELECT
CASE $CaseType = 1 $SystemType = 'Other'
CASE $CaseType = 2 $SystemType = 'Unknown'
CASE $CaseType = 3 $SystemType = 'Dekstop'
CASE $CaseType = 4 $SystemType = 'Low Profile Desktop'
CASE $CaseType = 5 $SystemType = 'Pizza Box'
CASE $CaseType = 6 $SystemType = 'Mini Tower'
CASE $CaseType = 7 $SystemType = 'Tower'
CASE $CaseType = 8 $SystemType = 'Portable'
CASE $CaseType = 9 $SystemType = 'Laptop'
CASE $CaseType = 10 $SystemType = 'Notebook'
CASE $CaseType = 11 $SystemType = 'Hand Held'
CASE $CaseType = 12 $SystemType = 'Docking Station'
CASE $CaseType = 13 $SystemType = 'All in One'
CASE $CaseType = 14 $SystemType = 'Sub Notebook'
CASE $CaseType = 15 $SystemType = 'Space-Saving'
CASE $CaseType = 16 $SystemType = 'Lunch Box'
CASE $CaseType = 17 $SystemType = 'Main System Chassis'
CASE $CaseType = 18 $SystemType = 'Expansion Chassis'
CASE $CaseType = 19 $SystemType = 'SubChassis'
CASE $CaseType = 20 $SystemType = 'Bus Expansion Chassis'
CASE $CaseType = 21 $SystemType = 'Peripheral Chassis'
CASE $CaseType = 22 $SystemType = 'Storage Chassis'
CASE $CaseType = 23 $SystemType = 'Rack Mount Chassis'
CASE $CaseType = 24 $SystemType = 'Sealed-Case PC'
ENDSELECT

? 'Manufacturer: '+$Mfg
? 'System Type: '+$SystemType
? 'Serial Number: '+$SerialNumb

FUNCTION WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x, Optional $root)
Dim $sQuery, $objEnum, $sValue, $sItem, $TMP, $SystemSet, $, $objInstance
If Not $sComputer $sComputer="." EndIf
if instr($sComputer,'\') $sComputer=right($sComputer,instrrev($sComputer,'\')) Endif
if not $root $root="\root\cimv2" Endif
$sQuery = "Select " + $sWhat + " From "+ $sFrom
If $sWhere AND $x $sQuery = $sQuery+" Where "+$sWhere+" = '"+$x+"'" EndIf
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$sComputer+$root)
If @ERROR Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf
$objEnum = $SystemSet.ExecQuery($sQuery)
If @ERROR Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf
For Each $objInstance in $objEnum
If $objInstance
$=Execute("$"+"sValue = $"+"objInstance."+$sWhat)
if VarType($sValue) & 8192
For Each $sItem in $sValue $tmp=$tmp+'|'+Trim($sItem) Next
else
$tmp=$tmp+'|'+Trim($svalue)
Endif
EndIf
Next
$WMIQuery = split(substr($tmp,2),'|')
Exit VAL("&"+Right(DecToHex(@ERROR),4))
ENDFUNCTION



[ 23. September 2003, 02:37: Message edited by: NTDOC ]

Top
#76801 - 2003-09-23 04:45 AM Re: How to Determine System Type - ie Laptop
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
code:
 
DIM $SysType[25]
$SysType=split('Other|Unknown|Dekstop|Low Profile Desktop|Pizza Box|Mini Tower|Tower|Portable|'+
'Laptop|Notebook|Hand Held|Docking Station|All in One|Sub Notebook|Space-Saving|'+
'Lunch Box|Main System Chassis|Expansion Chassis|SubChassis|Bus Expansion Chassis|'+
'Peripheral Chassis|Storage Chassis|Rack Mount Chassis|Sealed-Case PC','|')
$CaseType = WMIQuery('ChassisTypes','Win32_SystemEnclosure')[0]
$CaseType = $systype[val($CaseType)-1]



[ 23. September 2003, 04:46: Message edited by: Radimus ]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#76802 - 2003-09-23 04:58 AM Re: How to Determine System Type - ie Laptop
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
or

code:
 
DIM $SysType[25]
$SysType=split('Other|Unknown|Desktop|Low Profile Desktop|Pizza Box|Mini Tower|Tower|Portable|'+
'Laptop|Notebook|Hand Held|Docking Station|All in One|Sub Notebook|Space-Saving|'+
'Lunch Box|Main System Chassis|Expansion Chassis|SubChassis|Bus Expansion Chassis|'+
'Peripheral Chassis|Storage Chassis|Rack Mount Chassis|Sealed-Case PC','|')
$CaseType = WMIQuery('ChassisTypes','Win32_SystemEnclosure')[0]
? $systype[val($CaseType)-1]

Select
case ascan(split('8,9,10,12,14',','),$CaseType) $Case = 'Laptop'
case ascan(split('3,4,5,6,7,13,15,24',','),$CaseType) $Case = 'Desktop'
case 1 $Case = 'Unknown'
EndSelect



[ 23. September 2003, 04:59: Message edited by: Radimus ]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#76803 - 2003-09-23 05:11 AM Re: How to Determine System Type - ie Laptop
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
I like your first suggestion Rad. SPLIT should be much faster then a bunch of CASE statements.

The second version might not be that much of a time saver. My own personal preference is to get back the correct type and then I'll sort/edit in Excel if I want to show something in a report.

Top
#76804 - 2003-09-23 11:04 AM Re: How to Determine System Type - ie Laptop
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
but then remember that one the greatest reasons for this is that during scripting you need to know if a machine was a laptop or not...

if you used #2 and returned an unknown, you could then look for pcmcia and/or battery
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#76805 - 2003-09-23 04:21 PM Re: How to Determine System Type - ie Laptop
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
PCMCIA/Battery are not indicative of a laptop, unfortunately.
_________________________
There are two types of vessels, submarines and targets.

Top
#76806 - 2003-09-23 07:59 PM Re: How to Determine System Type - ie Laptop
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
I don't disagree that a main reason for this is not to find a Laptop/Notebook but once you return the data as a lump you have no way to then break it down into detail. If I get an UNKNOWN then I get one, your 2 method would not resolve that issue. I like having all the available detail and then breaking it down in Excel myself. Perhaps personal preference.

Good that there are now multiple methods here to use. [Big Grin]

Top
#76807 - 2003-09-23 11:31 PM Re: How to Determine System Type - ie Laptop
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
This is a nearly finished UDF, based on the previous posts in this topic.

How about keeping all hapy [Wink]

Create a function that returns a two element array contaning chassis type and description.

Chassis type would be:
  • Portable
  • Desktop
  • Server/Expansion
  • Unknown
  • Not found
Code and sample use:
code:
$st = SystemType('WS03')
'System type: ' + $st[0] ?
'System description: ' + $st[1] ?

Get $

Function SystemType(Optional $WS)
Dim $SysType,$oWMIService,$cItems,$Item,$cType

$cType = 0
$SystemType = 'Not Found'
$SysType = Split('Unknown|Other|Unknown|Desktop|Low Profile Desktop|Pizza Box|Mini Tower|Tower|Portable|'+
'Laptop|Notebook|Hand Held|Docking Station|All in One|Sub Notebook|Space-Saving|'+
'Lunch Box|Main System Chassis|Expansion Chassis|SubChassis|Bus Expansion Chassis|'+
'Peripheral Chassis|Storage Chassis|Rack Mount Chassis|Sealed-Case PC','|')
If Not $WS
$WS = "."
EndIf
$oWMIService = GetObject("winmgmts:\\" + $WS + "\root\cimv2")
If $oWMIService
$cItems = $oWMIService.ExecQuery("Select * from Win32_SystemEnclosure")
For Each $oItem In $cItems
For Each $Item In $oItem.ChassisTypes
$cType = Val($Item)
Next
Next
Select
Case AScan(Split('8,9,10,11,12,13,14',','),$cType) >= 0
$SystemType = 'Portable'
Case AScan(Split('3,4,6,7,15,24',','),$cType) >= 0
$SystemType = 'Desktop'
Case AScan(Split('5,16,17,18,19,20,21,22,23',','),$cType) >= 0
$SystemType = 'Server/Expansion'
Case 1
$SystemType = 'Unknown'
EndSelect
EndIf
$SystemType = Split($SystemType + Chr(9) + $SysType[$cType], Chr(9))
EndFunction

Any comments on whitch type belongs to whitch chassis type ?

-Erik

Top
#76808 - 2003-09-24 12:21 AM Re: How to Determine System Type - ie Laptop
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Looks pretty good Erik.

You need to add $oItem to the DIM list though.

Here is Post Prepped code for others to try if wanted.






DIM $Set1, $Set2,$ST
$Set1=SetOption('Explicit','ON')
$Set2=SetOption('NoVarsInStrings','ON')

$ST = SystemType()
'System type: ' + $st[0] ?
'System description: ' + $st[1] ?

Function SystemType(Optional $WS)
Dim $SysType,$oWMIService,$cItems,$Item,$cType,$oItem
$cType = 0
$SystemType = 'Not Found'
$SysType = Split('Unknown|Other|Unknown|Desktop|Low Profile Desktop|Pizza Box|Mini Tower|Tower|Portable|'+
'Laptop|Notebook|Hand Held|Docking Station|All in One|Sub Notebook|Space-Saving|'+
'Lunch Box|Main System Chassis|Expansion Chassis|SubChassis|Bus Expansion Chassis|'+
'Peripheral Chassis|Storage Chassis|Rack Mount Chassis|Sealed-Case PC','|')
If Not $WS
$WS = "."
EndIf
$oWMIService = GetObject("winmgmts:\\" + $WS + "\root\cimv2")
If $oWMIService
$cItems = $oWMIService.ExecQuery("Select * from Win32_SystemEnclosure")
For Each $oItem In $cItems
For Each $Item In $oItem.ChassisTypes
$cType = Val($Item)
Next
Next
Select
Case AScan(Split('8,9,10,11,12,13,14',','),$cType) >= 0
$SystemType = 'Portable'
Case AScan(Split('3,4,6,7,15,24',','),$cType) >= 0
$SystemType = 'Desktop'
Case AScan(Split('5,16,17,18,19,20,21,22,23',','),$cType) >= 0
$SystemType = 'Server/Expansion'
Case 1
$SystemType = 'Unknown'
EndSelect
EndIf
$SystemType = Split($SystemType + Chr(9) + $SysType[$cType], Chr(9))
EndFunction



Top
#76809 - 2005-01-21 12:25 AM Re: How to Determine System Type - ie Laptop
ClientMaster Offline
Fresh Scripter

Registered: 2005-01-19
Posts: 46
Loc: Tokyo, Japan
Hi,
This script is 99% what I was looking for. Thank you very much.
I just wanted to ask if anyone could help with a minor adjustment.
When the script runs, it returns the maker, type and serial.
I want to combine these to give a value.
e.g. IBM, Desktop, 12345abc to give output of id12345abc.
Is this possible?
_________________________
How can you know good, unless you experience bad.

Top
#76810 - 2005-01-21 02:49 AM Re: How to Determine System Type - ie Laptop
ClientMaster Offline
Fresh Scripter

Registered: 2005-01-19
Posts: 46
Loc: Tokyo, Japan
Well,
I have been able to answer my own question.
If anyone has any ideas on how to make it easier, they would be appreciated.


DIM $Set1, $Set2, $CaseType, $SystemType,$SerialNumb,$Mfg,$PCMAKER,$PCTYPE,$PCNAME
$Set1=SetOption('Explicit','ON')
$Set2=SetOption('NoVarsInStrings','ON')

$CaseType=WMIQuery('ChassisTypes','Win32_SystemEnclosure')[0]
$SerialNumb=WMIQuery('SerialNumber','Win32_BIOS')[0]
$Mfg=WMIQuery('Manufacturer','Win32_SystemEnclosure')[0]

SELECT
CASE $CaseType = 1 $SystemType = 'Other'
CASE $CaseType = 2 $SystemType = 'Unknown'
CASE $CaseType = 3 $SystemType = 'Dekstop'
CASE $CaseType = 4 $SystemType = 'Low Profile Desktop'
CASE $CaseType = 5 $SystemType = 'Pizza Box'
CASE $CaseType = 6 $SystemType = 'Mini Tower'
CASE $CaseType = 7 $SystemType = 'Tower'
CASE $CaseType = 8 $SystemType = 'Portable'
CASE $CaseType = 9 $SystemType = 'Laptop'
CASE $CaseType = 10 $SystemType = 'Notebook'
CASE $CaseType = 11 $SystemType = 'Hand Held'
CASE $CaseType = 12 $SystemType = 'Docking Station'
CASE $CaseType = 13 $SystemType = 'All in One'
CASE $CaseType = 14 $SystemType = 'Sub Notebook'
CASE $CaseType = 15 $SystemType = 'Space-Saving'
CASE $CaseType = 16 $SystemType = 'Lunch Box'
CASE $CaseType = 17 $SystemType = 'Main System Chassis'
CASE $CaseType = 18 $SystemType = 'Expansion Chassis'
CASE $CaseType = 19 $SystemType = 'SubChassis'
CASE $CaseType = 20 $SystemType = 'Bus Expansion Chassis'
CASE $CaseType = 21 $SystemType = 'Peripheral Chassis'
CASE $CaseType = 22 $SystemType = 'Storage Chassis'
CASE $CaseType = 23 $SystemType = 'Rack Mount Chassis'
CASE $CaseType = 24 $SystemType = 'Sealed-Case PC'
ENDSELECT

IF $MFG = "IBM"
$PCMAKER = "I"
ENDIF
IF $SystemType = "Low Profile Desktop"
$PCTYPE = "D"
ENDIF

$PCNAME = +$PCMAKER+$PCTYPE+$SerialNumb
? 'PCName: '+$PCNAME


FUNCTION WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x, Optional $root)
Dim $sQuery, $objEnum, $sValue, $sItem, $TMP, $SystemSet, $, $objInstance
If Not $sComputer $sComputer="." EndIf
if instr($sComputer,'\') $sComputer=right($sComputer,instrrev($sComputer,'\')) Endif
if not $root $root="\root\cimv2" Endif
$sQuery = "Select " + $sWhat + " From "+ $sFrom
If $sWhere AND $x $sQuery = $sQuery+" Where "+$sWhere+" = '"+$x+"'" EndIf
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$sComputer+$root)
If @ERROR Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf
$objEnum = $SystemSet.ExecQuery($sQuery)
If @ERROR Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf
For Each $objInstance in $objEnum
If $objInstance
$=Execute("$"+"sValue = $"+"objInstance."+$sWhat)
if VarType($sValue) & 8192
For Each $sItem in $sValue $tmp=$tmp+'|'+Trim($sItem) Next
else
$tmp=$tmp+'|'+Trim($svalue)
Endif
EndIf
Next
$WMIQuery = split(substr($tmp,2),'|')
Exit VAL("&"+Right(DecToHex(@ERROR),4))
ENDFUNCTION
_________________________
How can you know good, unless you experience bad.

Top
#76811 - 2005-01-21 09:10 PM Re: How to Determine System Type - ie Laptop
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Just an FYI about a typo that was pointed out to me

CASE $CaseType = 3 $SystemType = 'Dekstop'

Should be

CASE $CaseType = 3 $SystemType = 'Desktop'

I made a typo on Desktop

Top
#76812 - 2005-01-22 12:31 AM Re: How to Determine System Type - ie Laptop
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol, I didn't see it even though you said there was a typo!
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1607 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.068 seconds in which 0.033 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org