#76423 - 2003-08-19 05:01 PM
Inventory Client Service
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I have this script running as service on my client machines to generate an INI file containing inventory data. code:
break on
Do $nic=0 do $mygw=enumipinfo($nic,3) $ip=enumipinfo($nic,0) $NicDesc=enumipinfo($nic,2) select Case $mygw="192.168.84.129" $Location="01" $city="Pensacola" Case $mygw="192.168.61.17" $Location="02" $city="Panama City" Case $mygw="192.168.5.1" $Location="02" $city="St Augustine" Case $mygw="192.168.61.1" $Location="02" $city="Panama City" Case $mygw="192.168.200.129" $Location="03" $city="Alachua" Case $mygw="192.168.61.193" $Location="03" $city="Ocala" Case $mygw="192.168.61.225" $Location="03" $city="Ocala" Case $mygw="192.168.85.1" $Location="04" $city="Jacksonville" Case $mygw="192.168.39.129" $Location="05" $city="St Petersburg" Case $mygw="192.168.163.129" $Location="05" $city="St Petersburg" Case $mygw="192.168.34.1" $Location="06" $city="Tampa" Case $mygw="192.168.41.129" $Location="07" $city="Orlando" Case $mygw="192.168.103.1" $Location="08" $city="Ft Myers" Case $mygw="192.168.33.1" $Location="09" $city="W Palm Beach" Case $mygw="192.168.163.193" $Location="09" $city="W Palm Beach" Case $mygw="192.168.28.1" $Location="10" $city="Ft Lauderdale" Case $mygw="192.168.106.1" $Location="11" $city="Miami" Case $mygw="192.168.63.225" $Location="11" $city="Miami" Case $mygw="192.168.7.1" $Location="Killearn Ctr-2nd Fl" $city="TLH" Case $mygw="192.168.11.1" $Location="Bldg1-1st Fl" $city="TLH" Case $mygw="192.168.12.1" $Location="Bldg1-2nd Fl" $city="TLH" Case $mygw="192.168.13.1" $Location="Bldg1-3rd Fl" $city="TLH" Case $mygw="192.168.37.1" $Location="Bldg2-1st Fl" $city="TLH" Case $mygw="192.168.22.1" $Location="Bldg2-2nd Fl" $city="TLH" Case $mygw="192.168.31.1" $Location="Bldg3-1st Fl" $city="TLH" Case $mygw="192.168.32.1" $Location="Bldg3-2nd Fl" $city="TLH" Case $mygw="192.168.33.1" $Location="Bldg3-3rd Fl" $city="TLH" Case $mygw="192.168.34.1" $Location="Bldg3-1st Fl" $city="TLH" Case $mygw="192.168.35.1" $Location="Bldg3-2nd Fl" $city="TLH" Case $mygw="192.168.36.1" $Location="Bldg3-3rd Fl" $city="TLH" Case $mygw="192.168.42.1" $Location="Bldg4" $city="TLH" Case $mygw="192.168.56.1" $Location="TLH Servers" $city="TLH" Case $mygw="192.168.57.1" $Location="TLH RAS" $city="TLH" Case @ras $Location="RAS" $city="TLH" Case 1 $Location="00" $city="" endselect $nic=val($nic)+1 until $Location <> "00" or val($nic) > 10
$Mac =WMIQuery("MACAddress","Win32_NetworkAdapterConfiguration",,"Description",$NicDesc) $Mac =join(split($mac,':'),'') $Mac =left($mac,instr($mac,'|')-1) $HD =WMIQuery("Size","Win32_DiskDrive") $hdGB =left($hd,len($hd)-9) $hdMBfr =GetDiskSpace("c:")/1000 $Video =WMIQuery("Description","Win32_VideoController") $Printer=WMIQuery("DriverName","Win32_Printer",,"SystemName","@wksta") $modem =WMIQuery("Description","Win32_POTSModem",,"Status","OK") $Biosv =WMIQuery("SMBIOSBIOSVersion","Win32_BIOS") $biosd =WMIQuery("Version","Win32_BIOS") $Make =trim(split(WMIQuery("Manufacturer","Win32_ComputerSystem"))[0]) $Model =trim(WMIQuery("Model","Win32_ComputerSystem")) select case instr("$model","pro") $case="Desktop" case instr("$model","evo") $case="Desktop" case instr("$model","lat") $case="Laptop" case 1 $case="Not Specified" endselect $asset =WMIQuery("SMBIOSAssetTag","Win32_SystemEnclosure") if instr($asset,"|") for each $return in split($asset,"|") if $return $asset=$return endif next endif $SerNo =WMIQuery("SerialNumber","Win32_BIOS") if len($SerNo) < 2 $SerNo=WMIQuery("SerialNumber","Win32_SystemEnclosure") if instr($serno,"|") for each $return in split($serno,"|") if len($return)<10 $serno=$return endif next endif endif $SerNo =trim(ucase($SerNo)) $CPUsp =WMIQuery("CurrentClockSpeed","Win32_Processor") if instr($CPUsp,"239") $CPUsp=2400 endif if instr($CPUsp,"179") $CPUsp=1800 endif if instr($CPUsp,"106") $CPUsp=1100 endif if instr($CPUsp,"702") $CPUsp=700 endif if instr($CPUsp,"39") $CPUsp=400 endif $dimms =Split(WMIQuery("Capacity","Win32_PhysicalMemory"),"|") for $a=0 to ubound($dimms) $=execute("$$dimm$a=val($$dimms[$a]) / 1048576") $=execute("$$memory=val($$Memory)+val($$dimm$a)") next $ier =readvalue("HKLM\Software\Microsoft\Internet Explorer", "Version") $MSOdir =readvalue("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\excel.exe","Path") $access =getfileversion("$MSOdir\msaccess.exe") $excel =getfileversion("$MSOdir\excel.exe") $outlook =getfileversion("$MSOdir\outlook.exe") $powerpnt =getfileversion("$MSOdir\powerpnt.exe") $pub =getfileversion("$MSOdir\mspub.exe") $Word =getfileversion("$MSOdir\winword.exe") $vscanver =readvalue("HKLM\Software\Network Associates\TVD\VirusScan","szCurrentVersionNumber") $vscaneng =readvalue("HKLM\Software\Network Associates\TVD\Shared Components\VirusScan Engine\4.0.xx","szEngineVer") $vscandat =readvalue("HKLM\Software\Network Associates\TVD\Shared Components\VirusScan Engine\4.0.xx","szDatVersion")
if keyexist('HKLM\SOFTWARE\Cognos') $cogdir=readvalue('HKLM\SOFTWARE\Cognos','CognosIni') if right($cogdir,2)='..' $cogdir=split($cogdir,'..')[0] endif $impver=getfileversion($cogdir+'bin\impuser.exe') endif $aspenexe=readvalue('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ASE.exe','') if exist($aspenexe) $asefiletime=getfiletime($aspenexe) endif $acroexe=readvalue('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.exe','') if exist($acroexe) $acrobat=getfileversion($acroexe) endif
$keyindex = 0 $done = 0 $hotfix = '' do $subkeyindex = 0 $subdone = 0 $key = enumkey('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows 2000',$keyindex) if not @error do $subkey = enumkey('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows 2000\$key',$subkeyindex) if not @error $hotfix = $hotfix + ',' + $subkey else $subdone = 1 endif $subkeyindex = $subkeyindex + 1 until $subdone = 1 else $done = 1 endif $keyindex = $keyindex + 1 until $done $hotfix = right($Hotfix,len($hotfix)-1)
$rc = SRND(@ticks) $delay = 3600*8 ; minutes*hours $rdelay = rnd(3600)*@wdayno $delay = $rdelay + $delay ; minutes*random 1 - 7 hours
$=writevalue('HKLM\Software\Inventory Client','Last Inventory Date',@date,REG_SZ) $=writevalue('HKLM\Software\Inventory Client','Last Inventory Time',@time,REG_SZ) $=writevalue('HKLM\Software\Inventory Client','Next Inventory in Seconds',$delay,REG_SZ)
$=writeprofilestring("%windir%\Inventory.ini","Inventory","Date",@Date) $=writeprofilestring("%windir%\Inventory.ini","Inventory","Time",@time)
$=writeprofilestring("%windir%\Inventory.ini","Network","IPAddress",$IP) $=writeprofilestring("%windir%\Inventory.ini","Network","Mac",$Mac) $=writeprofilestring("%windir%\Inventory.ini","Network","Adapter",$NicDesc) $=writeprofilestring("%windir%\Inventory.ini","Network","Location",$location) $=writeprofilestring("%windir%\Inventory.ini","Network","City",$city)
$=writeprofilestring("%windir%\Inventory.ini","Hardware","ComputerName",@wksta) $=writeprofilestring("%windir%\Inventory.ini","Hardware","Make",$Make) $=writeprofilestring("%windir%\Inventory.ini","Hardware","Model",$Model) $=writeprofilestring("%windir%\Inventory.ini","Hardware","Case",$Case) $=writeprofilestring("%windir%\Inventory.ini","Hardware","SerialNumber",$SerNo) $=writeprofilestring("%windir%\Inventory.ini","Hardware","AHCATag",$Asset) $=writeprofilestring("%windir%\Inventory.ini","Hardware","BIOS",$Biosv) $=writeprofilestring("%windir%\Inventory.ini","Hardware","ProcessorSpeed",$CPUsp) $=writeprofilestring("%windir%\Inventory.ini","Hardware","HDSize",$hdGB) $=writeprofilestring("%windir%\Inventory.ini","Hardware","MBFree",$hdmbfr) $=writeprofilestring("%windir%\Inventory.ini","Hardware","Dimm0",$dimm0) $=writeprofilestring("%windir%\Inventory.ini","Hardware","Dimm1",$dimm1) $=writeprofilestring("%windir%\Inventory.ini","Hardware","Dimm2",$dimm2) $=writeprofilestring("%windir%\Inventory.ini","Hardware","Modem",$modem)
$=writeprofilestring("%windir%\Inventory.ini","Software","OS",@producttype) $=writeprofilestring("%windir%\Inventory.ini","Software","SP",@csd) $=writeprofilestring("%windir%\Inventory.ini","Software","Hotfixes",$hotfix) $=writeprofilestring("%windir%\Inventory.ini","Software","MSAccess",$access) $=writeprofilestring("%windir%\Inventory.ini","Software","MSExcel",$excel) $=writeprofilestring("%windir%\Inventory.ini","Software","MSOutlook",$outlook) $=writeprofilestring("%windir%\Inventory.ini","Software","MSPowerpoint",$powerpnt) $=writeprofilestring("%windir%\Inventory.ini","Software","MSPublisher",$pub) $=writeprofilestring("%windir%\Inventory.ini","Software","MSWord",$word) $=writeprofilestring("%windir%\Inventory.ini","Software","InternetExplorer",$ier) $=writeprofilestring("%windir%\Inventory.ini","Software","McAfeeVersion",$vscanver) $=writeprofilestring("%windir%\Inventory.ini","Software","McAfeeEngine",$vscaneng) $=writeprofilestring("%windir%\Inventory.ini","Software","McAfeeDAT",$vscandat) $=writeprofilestring("%windir%\Inventory.ini","Software","Impromptu",$Impver) $=writeprofilestring("%windir%\Inventory.ini","Software","AspenFiletime",$asefiletime) $=writeprofilestring("%windir%\Inventory.ini","Software","AdobeAcrobat",$acrobat)
$=logevent(0,18001,"Inventory Completed Successfully",,"Inventory Client")
sleep $delay until @error
;************************************************************************************************************************* FUNCTION WMIQuery($what,$from,optional $computer,optional $where, optional $x) dim $strQuery, $objEnumerator, $value if not $computer $computer="@WKSTA" endif $strQuery = "Select $what From $from" if $where and $x $strQuery = $strQuery + " Where $where = '$x'" endif $SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//$computer") $objEnumerator = $SystemSet.ExecQuery($strQuery) For Each $objInstance in $objEnumerator If @Error = 0 and $objInstance <> "" $=execute("$$value = $$objInstance.$what") $WMIQuery="$value"+"|"+"$WMIQuery" EndIf Next $WMIQuery=left($WMIQuery,len($WMIQuery)-1) exit @error ENDFUNCTION
The collected inventory is stored in an ini file into %windir%
|
|
Top
|
|
|
|
#76424 - 2003-08-19 05:03 PM
Re: Inventory Client Service
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
it runs under the local system account, so it has admin to collect the data.
this is the script the I have each machine run, so it will install
code:
copy '@scriptdir\InvClient.kix' %windir% copy '@scriptdir\wkix32.exe' %windir% copy '@scriptdir\srvany.exe' %windir%
shell 'cmd /c c:\temp\invclient\instsrv InvClient %windir%\srvany.exe'
$=writevalue('HKLM\SYSTEM\CurrentControlSet\Services\InvClient','Start','2',REG_DWORD) $=writevalue('HKLM\SYSTEM\CurrentControlSet\Services\InvClient\Parameters','Application','%windir%\wkix32.exe',REG_SZ) $=writevalue('HKLM\SYSTEM\CurrentControlSet\Services\InvClient\Parameters','AppParameters','%windir%\InvClient.kix',REG_SZ) shell 'cmd /c net start InvClient'
|
|
Top
|
|
|
|
#76425 - 2003-08-19 05:06 PM
Re: Inventory Client Service
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I remotely deployed it to the client machines using a rmtexec() script... in this case specifically, Remote Execution Manager.
and the command pushed was: kix32 c:\temp\invclient\setup.kix
|
|
Top
|
|
|
|
#76427 - 2003-08-19 05:12 PM
Re: Inventory Client Service
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
the invclient script may be modified in the future to upload directly to a SQL server database
Initally, the domain logon script will read the ini file and upload to a network inventory and be used in the script
|
|
Top
|
|
|
|
#76430 - 2003-08-23 08:42 PM
Re: Inventory Client Service
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
the inventory is collected by a kix script... stop the service, update the script start the service.
With the inventory local and run by the system acct, it has access to admin restricted resources like WMI and such.
The part that needs work is the upload into SQL... if that can be done via ODBC on the system acct.
With the read-only ini file for users (it is stored in %windir%) the remote inventory tools, like Inquisitor, or the one that DOC made up for help desk requests, can be very light weight as the inventory is already complete and easy to read from the ini file
|
|
Top
|
|
|
|
#76435 - 2003-09-06 05:14 AM
Re: Inventory Client Service
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
For one case...
my file: quote: DOS : 5.0 Specific OS : Windows 2000 Professional OS Suite : 0 OS Small Business : 0 OS Enterprise : 0 OS BackOffice : 0 OS CommServer : 0 OS Terminal Server : 0 OS Small Business : 0 OS Embedded NT : 0 OS DataCenter : 0 OS Single User TS : 0 OS Home Edition : 0 OS Blade Server : 0 Admin Rights : 1 SMS Client : 0 System Date : 2003/09/05 User Language : 0804Chinese System Language : 0804Chinese Rpcrt4.dll Version : 5.00.2195.6753 Working IP Address : 202.0.212.184 Working Subnet Mask : 255.255.255.0 Working Gateway : 202.0.212.1 Subnet : 202.0.212.0 Working MAC Address : B42320524153 Host Name : temp-pc Domain : FAI-xxx Windows 2000 Site : RAS Sessions : 0 VPN Session : 0 User : aa099672 Full Name : xxxx, Larry Logon Server : \\CN2SDB1 Logon Domain : AMPx1 Computer Name : TEMP-PC CSD : Service Pack 4 MS03-026 : 1 Cleaned : 0 SysRestore Stop : SysRestore disabled :
code:
use File::stat; use strict;
#my $ReportFile = "h:\\EPO-Report.txt"; my $ReportFile = "c:\\data\\scripts\\bug-Report.txt"; unlink $ReportFile;
my $fileCount=0;
foreach my $dir ("\\\\ambdc009\\log\$\\nachi","\\\\ambdc009\\log\$\\nachicleaned") { my $i=1; $fileCount++; opendir (F, $dir) || "Could not open directory: $dir\n"; my @filelist = readdir(F); closedir (F); my $date_string;
File: foreach my $file (@filelist) { my (@data,@data2,$field, $value,$computer); next File if $file eq "." or $file eq ".." ; if ($file =~ /(.*)\.txt/ and -e "$dir\\$file") {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(stat("$dir\\$file")->mtime); $year += 1900; $mon += 1; $date_string = sprintf( "%04d/%02d/%02d %02d:%02d:%02d", $year, $mon, $mday, $hour, $min, $sec); push @data, ["LogonTime(GMT -4)", $date_string];
open (F, "<$dir\\$file"); while(<F>) { chomp; ($field, $value) = $_ =~ /^(\w[\w\s\.\-]+\w)\s+\:([\s\w\.].*?)$/; next if $field eq ""; $value =~ s/^\s+//; push @data, [$field, $value]; } close F; } $field = ""; $value = ""; if (scalar(@data) < 34) { print "\n$file\n"; next; } if ($i==1 and $fileCount ==1) { map { push @data2, $$_[0]} @data; $data2[9] = 'OS Small Business (Restricted)'; $field = join("~", @data2); &Log($field); }
@data2 = (); map { push @data2, $$_[1]} @data; $value = join("~", @data2); print "\r$i of " . (scalar(@filelist)-2); &Log($value); #unlink "$dir\\$file"; $i++; } print "\n"; }
sub Log { my $text = shift; open (R, ">>$ReportFile") || die "Could not open $ReportFile\n"; print R "$text\n"; close R; }
|
|
Top
|
|
|
|
#76436 - 2003-09-06 05:37 AM
Re: Inventory Client Service
|
JohnQ
Starting to like KiXtart
Registered: 2003-03-04
Posts: 171
|
Ok, you lost me Howard. You could have written that thing in Japanese and it wouldn't have made less sense to me.
Thanks for all of your help. Anytime I post a question, I love to see that little airplane on the left hand side of the screen - I know I've gotten a good reply. [ 06. September 2003, 05:37: Message edited by: JohnQ ]
|
|
Top
|
|
|
|
#76437 - 2003-09-06 06:34 AM
Re: Inventory Client Service
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Sorry, didn't mean to get you lost in that Perl code. That code can be fairly easily written in KiX code. I use Perl because I compile it and can give it to the people that wanted the data. Makes it easy for them.
The data file listed first is what is written from my KiXtart logon script. I use the ":" and "white space" as the delimiter that separates the data field name and the value.
The second part of the post is my quick change Perl code that (basically): 1. loops through the listed directories 2. opens the directories and collectes the file names 3. opens the file 4. reads each line 5. splits the line using Regular expressions loading $field and the $value vars. 6. pushes the values into an array of arrays 7. joins the array values with the "~" delimiter 8. Write the file.
The output file (lines broken for display):
code:
LogonTime(GMT -4)~DOS~Specific OS~OS Suite~OS Small Business~OS Enterprise~OS BackOffice~OS CommServer~ OS Terminal Server~OS Small Business (Restricted)~OS Embedded NT~OS DataCenter~OS Single User TS~OS Home Edition~ OS Blade Server~Admin Rights~SMS Client~System Date~User Language~System Language~Rpcrt4.dll Version~ Working IP Address~Working Subnet Mask~Working Gateway~Subnet~Working MAC Address~Host Name~Domain~ Windows 2000 Site~RAS Sessions~VPN Session~User~Full Name~Logon Server~Logon Domain~Computer Name~CSD~ MS03-026~Cleaned~SysRestore Stop~SysRestore disabled 2003/09/03 08:55:45~5.0~Windows 2000 Professional~0~0~0~0~0~0~0~0~0~0~0~0~0~0~2003/09/03~0810Italian~ 0409English~5.00.2195.5419~162.109.127.48~255.255.255.128~162.109.127.1~162.109.127.0~006008B37474~2k-nbquality~ LUG-CH~~0~0~GL000636~Lorenz, Elena~\\EMADH2~AMPx1~2K-NBQUALITY~Service Pack 3~0~0~~ 2003/08/28 11:28:38~5.0~Windows 2000 Professional~0~0~0~0~0~0~0~0~0~0~0~0~1~1~2003/08/28~0409English~ 0409English~5.00.2195.6753~169.254.101.152~255.255.0.0~~169.254.0.0~006008ED72F4~apandini.us.tycoelectronics.com~ US-TYCO-E~US-CA-ELCON~0~0~US055712~Pandi, Lucia~\\AMBDC105~AMPx1~APANDINI~Service Pack 3~1~0~~
[ 06. September 2003, 06:39: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#76438 - 2003-09-06 10:53 AM
Re: Inventory Client Service
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I suppose that I could rewrite the read\writeprofilestring to use Readfile()/Writefile(), but as the file is local to the machine it is no great deal...
INI files are just a quick and easy of doing the output. What is the CPU speed? readprofilestring("%windir%\Inventory.ini","Hardware","ProcessorSpeed")... saves me from have to read and parse with my code and have MS do it for me...
Each machine will have only 1 file, as I control the input and the output (and the horizontal and the vertical..) I will not be 'parsing' for anything. I would just read every element possible (nulls will be dealt with...) and then do individual updates to 3 SQL tables, Hardware, Software, and Network... Using the handy DB UDFs
I haven't done much this way, since I'm caught up the damn blaster/nachi updates, the VB code update which means I have to deploy SP3 first...
|
|
Top
|
|
|
|
#76439 - 2003-09-06 01:25 PM
Re: Inventory Client Service
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Rad-man, I only bring up the INI issue because a remote network share was mentioned. There probably is only a measurable difference if the Reading and writing crosses a WAN as in the environment I program.
Since I have everyone worldwide write to a single server for these special projects, I wanted to optimize the network traffic.
|
|
Top
|
|
|
|
#76440 - 2003-09-06 03:16 PM
Re: Inventory Client Service
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
Doc does something like: writes everything on single line comma seperated, on the local machine, named @wksta.csv.
Then the script copies the file to a network share
Doc then manually runs an admin bat file that copy appends all the files together into a big csv that is eventualy read with excel.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|