#65240 - 2002-05-03 09:42 PM
Hardware Inventory (work in progress, RFC)
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
I'm currently working on a hardware inventory script based on WMI with the ultimate goal to put everything into a database. Right now, I created a WMI property parser that reads the hardware values to be captured from a .INI file. If interested, please comment this idea.
Here's the UDF, the variable '$configfile' must point to the file HARDWAREINVENTORY.INI code:
;FUNCTION HardwareInventory() ; ;ACTION Creates an hardware inventory as a .INI file ; ;AUTHOR Jens Meyer (sealeopard@usa.net) ; ;SYNTAX RETCODE = HARDWAREINVENTORY() ; ;PARAMETERS none ; ;RETURN 0 if successful, otherwise error code ; ;REMARKS requires WMI, hardware inventory is controlled by HARDWAREINVENTORY.INI ; ;DEPENDENCIES WMIQuery() @ http://kixtart.org/cgi-bin/ultimatebb.php?ubb=get_topic;f=12;t=000117 ; BSort() @ http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000070 ; AVal() @ http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000192 ; ;EXAMPLE $retcode = HardwareInventory('hardware.ini') ; ;KIXTART BBS ; function HardwareInventory($filename) Dim $retcode, $configfile, $sections, $hardwarecomponent, $hardwareentry, $entries Dim $translate, $discriminator, $wmientry, $entrynumber, $wmientryarray Dim $translatedvalues, $parentarray, $counter, $isparent
$configfile=fullfile($SCRIPTDIRECTORY,'ini/hardwareinventory.ini') $discriminator='_Values'
if not exist($configfile) exit 2 endif
$sections=split(readprofilestring($configfile,'',''),chr(10)) if $sections[ubound($sections)]='' redim preserve $sections[ubound($sections)-1] endif
for each $hardwarecomponent in $sections ? 'Processing hardware component '+$hardwarecomponent
$entries=readprofilestring($configfile,$hardwarecomponent,'') if $entries<>'' $entries=split($entries,chr(10)) if $entries[ubound($entries)]='' redim preserve $entries[ubound($entries)-1] endif $entries=bsort($entries)
redim $translate[0] if ubound($entries)>0 while instr($entries[ubound($entries)],$discriminator) $translate[ubound($translate)]=left($entries[ubound($entries)], len($entries[ubound($entries)])-len($discriminator)) redim preserve $translate[ubound($translate)+1] redim preserve $entries[ubound($entries)-1] loop if ubound($translate)>0 redim preserve $translate[ubound($translate)-1] endif endif $entries=bsort(aval($entries)) if vartype($entries)<8192 $retcode=$entries redim $entries[0] $entries[0]=$retcode endif
$parentarray='' for each $entrynumber in $entries $value=readprofilestring($configfile,$hardwarecomponent,$entrynumber) if instr($value,',') $value=split($value,',') $hardwareentry=trim($value[0]) $format=trim($value[1]) else $hardwareentry=trim($value) $format='' endif $wmientryarray=wmiquery($hardwareentry,$hardwarecomponent)
if vartype($parentarray)<8192 and instr($wmientryarray,'|') $parentarray=split($wmientryarray,'|') $isparent=1 else $isparent=0 endif $wmientryarray=split($wmientryarray,'|') if vartype($parentarray)=>8192 if ubound($wmientryarray)<>ubound($parentarray) redim preserve $wmientryarray[ubound($parentarray)] for $counter=1 to ubound($parentarray) $wmientryarray[$counter]=$wmientryarray[0] next endif endif $counter=0 for each $wmientry in $wmientryarray select case $format='serialnumber' if len($wmientry)=20 $wmientry=''+left($wmientry,5)+'-'+substr($wmientry,6,3)+ '-'+substr($wmientry,10,7)+'-'+right($wmientry,3) endif $wmiformat='' case $format='datetime' $wmientry=''+left($wmientry,4)+'-'+substr($wmientry,5,2)+ '-'+substr($wmientry,7,2)+' '+substr($wmientry,9,2)+':'+substr($wmientry,11,2)+':'+substr($wmientry,13,2) $wmiformat='' case $format='date' $wmientry=''+left($wmientry,4)+'-'+substr($wmientry,5,2)+ '-'+substr($wmientry,7,2) $wmiformat='' case $format='bytes' $wmientry=val($wmientry)/1048576 $wmiformat='MB' case isinarray($hardwareentry,$translate) $translatedvalues=readprofilestring($configfile,$hardwarecomponent,$hardwareentry+$discriminator) $translatedvalues=split($translatedvalues,',') if val($wmientry)<=ubound($translatedvalues) $wmientry=''+$wmientry+' = '+trim($translatedvalues[val($wmientry)]) endif $wmiformat='' case 1 $wmiformat=$format endselect if $wmientry='' $wmientry='n/a' endif $wmientry=trim(''+$wmientry+' '+trim($wmiformat)) $wmientry=$hardwareentry+' - '+$wmientry
if vartype($parentarray)=>8192 if not $isparent $wmientry='parent='+$parentarray[$counter]+' '+$wmientry endif endif
? $wmientry $counter=$counter+1 next next endif next exit @ERROR endfunction
And here's the initialization file: code:
; configuration file for WMI hardware inventory ; ; standard structure for each hardware device: ; [Class Name] ; 0=Property, Format ; Property_Values=value1,value2 ; ; Definitions: ; Class Name = Computer System Hardware Classes according to the WMI documentation ; Property = Property for a specific device class ; Format = optional formatting instructions, e.g. 'datetime' will reformat the property value ; to standard Kixtart date/time format and 'bytes' will reformat the value to 'MB' ; Property_Values = Certain properties return a value that can be translated into a more informative ; string with a look-up table. This field contains the look-up table according to the ; WMI documentation. For example, Win32_Processor.Architecture returns a value between ; 0 and 3. Therefore, the 0-based look-up table contains the corresponding values 'x86, ; MIPS,Alpha,PowerPC' ; ; If multiple values are returned, e.g. for two harddisks, then the first property will become the parent ; property. All properties are being processed according to their number from 0 upwards.
[Win32_OperatingSystem] 0=Caption 1=Manufacturer 2=Version 3=BuildNumber 4=BuildType 5=SerialNumber, serialnumber 6=OSLanguage 7=CSDVersion 8=WindowsDirectory 9=SystemDirectory 10=InstallDate, datetime 11=LastBootupTime, datetime 12=RegisteredUser 13=Organization
[Win32_ComputerSystem] 0=Manufacturer 1=Model
[Win32_BIOS] 0=SerialNumber 1=SMBIOSBIOSVersion 2=Version 3=BiosVersion 4=BuildNumber 5=Manufacturer 6=Name 7=ReleaseDate, date
[Win32_Processor] 0=manufacturer 1=description 2=CurrentClockSpeed, MHz 3=maxclockspeed, MHz 4=l2cachesize, KB 5=l2cachespeed, MHz 6=deviceid 7=uniqueid 8=Family Family_Values=n/a,Other,Unknown,8086,80286,80386,80486,8087,80287,80387,80487, Pentium Family,Pentium Pro,Pentium II,Pentium MMX,Celeron,Pentium II Xeon,Pentium III, M1 Family,M2 Family,K5 Family,K6 Family,K6-2,K6-III,Athlon,Power PC Family,Power PC 601, Power PC 603,Power PC 603+,Power PC 604,Alpha Family,MIPS Family,SPARC Family,68040,6 8xxx Family,68000,68010,68020,68030,Hobbit Family,Weitek,PA-RISC Family,V30 Family, Pentium III Xeon,AS400 Family, IBM390 Family,i860,i960,SH-3,SH-4,ARM,StrongARM,6x86,MediaGX,MII,WinChip
[Win32_LogicalMemoryConfiguration] 0=TotalPhysicalMemory, KB 1=TotalVirtualMemory, KB 2=TotalPageFileSpace, KB
[Win32_PhysicalMemory] 0=BankLabel 1=Capacity, Bytes 2=MemoryType 3=Speed, ns MemoryType_Values=n/a,Unknown,Other,DRAM, Synchronous DRAM,Cache DRAM,EDO,EDRAM,VRAM,SRAM,RAM,ROM,Flash, EEPROM,FEPROM,EPROM,CDRAM,3DRAM,SDRAM,SGRAM
[Win32_DiskDrive] 0=name 1=manufacturer 2=model 3=interfacetype 4=size, Bytes 5=partitions
[Win32_1394Controller] 0=name 1=manufacturer 2=description
Finally, the output for my computer based on the above posted configuration file: code:
Processing hardware component Win32_OperatingSystem Caption - Microsoft Windows 2000 Professional Manufacturer - Microsoft Corporation Version - 5.0.2195 BuildNumber - 2195 BuildType - Uniprocessor Free SerialNumber - xxxxx-xxx-xxxxxx-xxx OSLanguage - 1033 CSDVersion - Service Pack 2 WindowsDirectory - C:\WINNT SystemDirectory - C:\WINNT\System32 InstallDate - 2002-04-10 17:40:44 LastBootupTime - 2002-05-02 13:27:23 RegisteredUser - xxxxx Organization - xxxxx Processing hardware component Win32_ComputerSystem Manufacturer - Gateway Model - MP44BX Processing hardware component Win32_BIOS SerialNumber - 0015587801 SMBIOSBIOSVersion - 4M4PB0X1.15A.0033.P21 Version - PhoenixBIOS 4.0 Release 6.0 BiosVersion - n/a BuildNumber - n/a Manufacturer - Intel Corp. Name - Default System BIOS ReleaseDate - 1999-11-30 Processing hardware component Win32_Processor manufacturer - GenuineIntel description - x86 Family 6 Model 7 Stepping 3 CurrentClockSpeed - 450 MHz maxclockspeed - 1200 MHz l2cachesize - 512 KB l2cachespeed - 225 MHz deviceid - CPU0 uniqueid - 0000-0673-0001-3AB9-7DF8-3226 Family - 17 = Pentium III Processing hardware component Win32_LogicalMemoryConfiguration TotalPhysicalMemory - 196132 KB TotalVirtualMemory - 765816 KB TotalPageFileSpace - 569684 KB Processing hardware component Win32_PhysicalMemory BankLabel - BANK 2 BankLabel - BANK 1 parent=BANK 2 Capacity - 64 MB parent=BANK 1 Capacity - 128 MB parent=BANK 2 MemoryType - 4 = Synchronous DRAM parent=BANK 1 MemoryType - 4 = Synchronous DRAM parent=BANK 2 Speed - n/a ns parent=BANK 1 Speed - n/a ns Processing hardware component Win32_DiskDrive name - \\.\PHYSICALDRIVE1 name - \\.\PHYSICALDRIVE0 parent=\\.\PHYSICALDRIVE1 manufacturer - (Standard disk drives) parent=\\.\PHYSICALDRIVE0 manufacturer - (Standard disk drives) parent=\\.\PHYSICALDRIVE1 model - IOMEGA ZIP 100 parent=\\.\PHYSICALDRIVE0 model - QUANTUM FIREBALL CX13.6A parent=\\.\PHYSICALDRIVE1 interfacetype - IDE parent=\\.\PHYSICALDRIVE0 interfacetype - IDE parent=\\.\PHYSICALDRIVE1 size - n/a MB parent=\\.\PHYSICALDRIVE0 size - 772 MB parent=\\.\PHYSICALDRIVE1 partitions - n/a parent=\\.\PHYSICALDRIVE0 partitions - 2 Processing hardware component Win32_1394Controller name - n/a manufacturer - n/a description - n/a
Remark: Physical harddisk sizes are cureently repoered incorrectly, will be resolved when Kixtart 4.10 is released. The numbers get too big ;-) [ 24 May 2002, 16:35: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#65241 - 2002-05-04 12:07 AM
Re: Hardware Inventory (work in progress, RFC)
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Jens,
Not to put anybody on the spot here. CJ raised the question once upon a time - where to get the WMICORE files from?
http://www.microsoft.com/downloads/release.asp?ReleaseID=18490
Maybe incorporate a check to see if these are in place?
Other than that.. It looks really schweet!
HTH,
- Kent
|
|
Top
|
|
|
|
#65243 - 2002-05-07 04:29 AM
Re: Hardware Inventory (work in progress, RFC)
|
mschipper
Fresh Scripter
Registered: 2002-05-07
Posts: 10
Loc: Adelaide
|
Cool..
Thats awesome dude. I've been looking for something like this for ages. I would be very interested to see how it turns out.
If you could also incorporate the IE build and maybe some sort of "Q" patch level. That would save everyone alot of time.
Well done dude.. ill buy you a beer..
MARK.
|
|
Top
|
|
|
|
#65247 - 2002-05-23 08:02 PM
Re: Hardware Inventory (work in progress, RFC)
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Good job. A new point of catching client information. We will give it also a try. greetings.
|
|
Top
|
|
|
|
#65248 - 2002-05-24 02:40 AM
Re: Hardware Inventory (work in progress, RFC)
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
When did this happen ??
At sometime the BBS software on this site has been updated, with the result, that if a single post in a topic containes very long lines inside the [Code] / [/Code] section, the hole topic gets wery wide. All other posts in this topic gets expanded sideways, so you have to do a lot of scrolling to read the posts.
An example from this topic is sealeopard's first post in this topic:code:
MemoryType_Values=n/a,Unknown,Other,DRAM,Synchronous DRAM,Cache DRAM,EDO,EDRAM,VRAM,SRAM,RAM,ROM,Flash,EEPROM,FEPROM,EPROM,CDRAM,3DRAM,SDRAM,SGRAM
This is not adressed to you, sealeopard But to the BBS
-Erik
|
|
Top
|
|
|
|
#65249 - 2002-05-24 03:25 AM
Re: Hardware Inventory (work in progress, RFC)
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Erik,
There is hope.
Click the "Printer Friendly View" to see it proper.
Regards,
- Kent
|
|
Top
|
|
|
|
#65250 - 2002-05-24 08:29 PM
Re: Hardware Inventory (work in progress, RFC)
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
Thank you Kent,
That helps a lot.
How about a button for "Browser friendly view"
-Erik
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|