Page 1 of 1 1
Topic Options
#103649 - 2003-08-11 08:06 PM Inventory Script
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I am writing an Inventory script to run as a service on all my client machines using the system account.

It logs all the inventory data to %windir% as an INI file

I will eventually be writing the data to a SQL server.

What I'm curious of is your experience in similar things:
Should I have the Inventory client also write the SQL data? (the PC may be off-line for extended periods of time, like laptops in the field)
Should I write a seperate upload client script/service, utilizing the VPN detection script?
How often should each client run? If I have it run every 24 hours, it would eventually just run at startup for everyone.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#103650 - 2003-08-11 08:11 PM Re: Inventory Script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The SYSTEM account, IIRC, does not have network access rights, thus you'll need to run the upload script under a different account.
_________________________
There are two types of vessels, submarines and targets.

Top
#103651 - 2003-08-11 08:18 PM Re: Inventory Script
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Has anyone had any experience in have a kix script sleep for long periods of time... like hours?

$rc = SRND(@MSECS)
$delay = 60*60*10 + 60*60*rnd(@wdayno)
sleep $delay

Thanks Jens, I guess the simplest solution would be to have the upload script run at logon... I dunno if network will give me a domain user acct
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#103652 - 2003-08-11 08:34 PM Re: Inventory Script
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
BTW, Here is what I have so far.. I plan on SRVANYing this

Ideas/Suggestions?

code:
 
break on

Do
$LastDate=readvalue('HKLM\Software\Inventory Client','Last Inventory Date')
$LastTime=readvalue('HKLM\Software\Inventory Client','Last Inventory Time')
$timediff=datetimediff($LastDate+' '+$LastTime)
$hours=split(split($timediff)[1],':')[0]
if val($hours)
$nic=0
do
$mygw=enumipinfo($nic,3) $ip=enumipinfo($nic,0) $NicDesc=enumipinfo($nic,2)
select
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")

$=writevalue('HKLM\Software\Inventory Client','Last Inventory Date',@date,REG_SZ)
$=writevalue('HKLM\Software\Inventory Client','Last Inventory Time',@time,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","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)

endif
$rc = SRND(@MSECS)
$delay = 60*60*10 + 60*60*rnd(@wdayno) ;seconds*minutes*hours + seconds*minutes*random 1 - 7 hours
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
;*************************************************************************************************************************
function datetimediff($time1,optional $time2)
Dim $date1, $date2, $datediff, $timediff

$datetimediff=''
if not instr($time1,' ')
select
case instr($time1,'/') $time1=$time1+' 00:00:00.000'
case instr($time1,':') $time1=@DATE+' '+$time1
case 1 exit 87
endselect
endif
if not instr($time2,' ')
select
case instr($time2,'/') $time2=$time2+' '+@TIME+'.'+right('000'+@MSECS,3)
case instr($time2,':') $time2=@DATE+' '+$time2
case 1 $time2=@DATE+' '+@TIME+'.'+right('000'+@MSECS,3)
endselect
endif
$time1=split($time1,' ') $date1=$time1[0] $time1=$time1[1]
$time2=split($time2,' ') $date2=$time2[0] $time2=$time2[1]

$datediff=serialdate($date2)-serialdate($date1)
$timediff=serialtime($time2)-serialtime($time1)
if $timediff=>86400
$timediff=$timediff-86400
$datediff=$datediff+1
endif
$datediff=serialdate(serialdate('0000/00/00')+$datediff-1)
$timediff=serialtime($timediff)

$datetimediff=$datediff+' '+$timediff
exit 0
endfunction
;*************************************************************************************************************************
function serialdate($ExpD)
dim $z,$h,$a,$b,$c,$y,$m,$d
if instr($ExpD,'/')
$ExpD=split($ExpD,'/')
$y=val($ExpD[0])
$m=val($ExpD[1])
$d=val($ExpD[2])
if $m<3
$m=$m+12
$y=$y-1
endif
$SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
else
$z=0+$ExpD+306
$h=100*$z-25
$a=$h/3652425
$b=$a-$a/4
$y=(100*$b+$h)/36525
$c=$b+$z-365*$y-$y/4
$m=(5*$c+456)/153
$d=$c-(153*$m-457)/5
if $m>12
$y=$y+1
$m=$m-12
endif
$SerialDate=right('0000'+$y,4)+'/'+right('00'+$m,2)+'/'+right('00'+$d,2)
endif
endfunction

;*************************************************************************************************************************
function serialtime($strtime)
dim $hours, $minutes, $seconds, $milliseconds

if instr($strtime,':')
$strtime=split($strtime,':')
select
case ubound($strtime)<3
redim preserve $strtime[3]
if instr($strtime[2],'.')
$strtime[3]=right($strtime[2],len($strtime[2])-instr($strtime[2],'.'))
$strtime[2]=left($strtime[2],instr($strtime[2],'.')-1)
else
$strtime[3]=0
endif
case ubound($strtime)>3
$serialtime=-1
exit 87
endselect

$hours=val($strtime[0])
if $hours<0 or $hours>23 $serialtime=-1 exit 87 endif
$minutes=val($strtime[1])
if $minutes<0 or $minutes>59 $serialtime=-1 exit 87 endif
$seconds=val($strtime[2])
if $seconds<0 or $seconds>59 $serialtime=-1 exit 87 endif
$milliseconds=cdbl($strtime[3])
if $milliseconds<0 or $milliseconds>999 $serialtime=-1 exit 87 endif
$serialtime=0.0+($hours*3600)+($minutes*60)+($seconds)+($milliseconds/1000)
else
$strtime=val(cdbl($strtime)*1000)
if $strtime<=86400000 and $strtime>=0
$hours=$strtime/3600/1000
$strtime=$strtime-($hours*3600*1000)
$hours=right('00'+$hours,2)
$minutes=$strtime/60/1000
$strtime=$strtime-($minutes*60*1000)
$minutes=right('00'+$minutes,2)
$seconds=$strtime/1000
$strtime=$strtime-($seconds*1000)
$seconds=right('00'+$seconds,2)
$milliseconds=left($strtime,3)
$milliseconds=right('000'+$milliseconds,3)
$serialtime=$hours+':'+$minutes+':'+$seconds+'.'+$milliseconds
else
$serialtime='-1'
exit 87
endif
endif
endfunction

;*************************************************************************************************************************


_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#103653 - 2003-08-11 08:42 PM Re: Inventory Script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
rad, have you ever used bbChecker?

it's been ran for weeks without any problems.

also, my backup script sits on 24/7 on server and no problems happened this far.

and as it's control is in ini-file, it can be ran as kix-scheluder service.
_________________________
!

download KiXnet

Top
#103654 - 2003-08-11 08:43 PM Re: Inventory Script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Why not have the script reschedule itself via Task Scheduler or set a Task scheduler task to repeat every xx minutes/hours?
_________________________
There are two types of vessels, submarines and targets.

Top
#103655 - 2003-08-11 08:58 PM Re: Inventory Script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
You could also do something in the reverse process.

Write a small log file out to a server and have an admin script parse that folder looking for files.

When it finds it, it would then run a remote admin script against the client to collect the data and input to SQL at that time.

Then the process would delete the file. You could even add other date or times flags in the registry in case you did not want to run it EVERY logon.

Top
#103656 - 2003-08-11 09:15 PM Re: Inventory Script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, task scheluder also takes processor power.
if one has scheluder script he can disable the scheluder service.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
0 registered and 978 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.058 seconds in which 0.024 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