Well, after stealing some ideas and code from BoxKite and working with Bryce (Bryce did all the work) Here is a FAST method of doing an inventory on the installed software for a system.
You don't need the running time $aStart or $aStop, but I added to test the speed. On my system which has 195 entries, it completes the task in .78 seconds. Using other methods of writing a file first and then sorting it takes about 3 seconds. Using the old Csort method takes about 20 seconds.
code:
; GetInstalledSoftware.kix
; Idea borrowed/stolen from BoxKite
; Modifications made by NTDOC
; Very cool array and final coding by Bryce
; The Function CombSort is by Shawn
break on
$aStart=@ticks
$outfile = "c:\temp\@wksta.log"
$software = combsort(getinstalledsoftware)
if exist($outfile)
del $outfile
endif
$ = open(1, $outfile,5)
for each $item in $software
$ = writeline(1,$item+@crlf)
next
$ = close(1)
$aStop=@ticks
? "Script Running Time is: " $aStop-$aStart
exit(0)
function GetInstalledsoftware
dim $softwarekey, $index
dim $temparray[10]
$SoftwareKey = enumkey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\",$Index)
while not @error
$DisplayName = readvalue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$SoftwareKey","displayname")
$DisplayVersion = readvalue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$SoftwareKey","DisplayVersion")
if $DisplayName
if $count > ubound($temparray)
redim preserve $temparray[ubound($temparray)+10]
endif
$temparray[$count] = $DisplayName +" "+ $DisplayVersion
$count = $count + 1
endif
$Index = $Index + 1
$SoftwareKey = enumkey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\",$Index)
loop
if $count > 0
redim preserve $temparray[$count-1]
else
$temparray = ""
endif
$getinstalledsoftware = $temparray
endfunction
Function CombSort($v, Optional $o)
Dim $i,$j,$m,$s,$g
$n=UBound($v)
$g = $n
If $g
While $g > 1 Or Not $s
$g=($g*1000)/1279
If $g < 1
$g = 1
EndIf
$s=1
For $i = 0 To $n-$g
$j=$i+$g
If ($v[$i] > $v[$j] And Not $o) Or ($v[$i] < $v[$j] And $o)
$m = $v[$i]
$v[$i] = $v[$j]
$v[$j] = $m
$s=0
EndIf
Next
Loop
$CombSort = $v
Else
$CombSort = 0
EndIf
EndFunction
[ 29. August 2002, 09:49: Message edited by: NTDOC ]