BradV
Seasoned Scripter
  
Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
|
Allen, you're correct. I was single stepping through, saw the error and quit. I came up with the following function:
Function GetAllPatches(optional $strWks)
; Function: GetAllPatches
;
; Author: Brad Van Orden
; Tremendous assist from Allen Powell
;
; Version: 1.1
;
; Version History: 21 November 2011, finished initial version
; 21 November 2011, Added code to remove carriage returns
; and line feeds from the description.
;
; Action: Returns an array of all the updates on a given system.
;
; Syntax: GetAllPatches([$strWks])
;
; Parameters: Optional name of a remote system to query.
; If omitted, will query the current system.
;
; Returns: Array listing all updates and their status.
;
; Dependencies: None
;
; Kixtart version: tested with 4.61
;
Dim $objSession, $objSearcher, $objUpdate, $colUpdates, $intI, $objSC, $intHistoryCount
Dim $objIdentity, $objCodeO, $arrPatch[5,1], $intCount
;
If $strWks = ""
$strWks = "."
EndIf
;
$objSC = CreateObject("ScriptControl")
$objSC.Language = "VBScript"
$objSC.AddCode('Set Session = CreateObject("Microsoft.Update.Session","' + $strWks + '")')
$objSC.Run
$objCodeO = $objSC.CodeObject
$objSession = $objCodeO.Session
$objSearcher = $objSession.CreateUpdateSearcher
$intHistoryCount = $objSearcher.GetTotalHistoryCount
$colUpdates = $objSearcher.QueryHistory(0, $intHistoryCount)
$intCount = 0
$arrPatch[0,$intCount] = "Title"
$arrPatch[1,$intCount] = "Description"
$arrPatch[2,$intCount] = "Update Application Date"
$arrPatch[3,$intCount] = "Operation Type"
$arrPatch[4,$intCount] = "Operation Result"
$arrPatch[5,$intCount] = "Update ID"
$intCount = $intCount + 1
For Each $objUpdate in $colUpdates
$arrPatch[0,$intCount] = $objUpdate.Title
$arrPatch[1,$intCount] = Join(Split(Join(Split($objUpdate.Description,Char(13))),Chr(10)))
$arrPatch[2,$intCount] = $objUpdate.Date
$intI = $objUpdate.Operation
Select
Case $intI = 1
$arrPatch[3,$intCount] = "Installation"
Case $intI = 2
$arrPatch[3,$intCount] = "Uninstallation"
Case 1
$arrPatch[3,$intCount] = "Could not be determined"
EndSelect
$intI = $objUpdate.ResultCode
Select
Case $intI = 0
$arrPatch[4,$intCount] = "The operation has not started."
Case $intI = 1
$arrPatch[4,$intCount] = "The operation is in progress."
Case $intI = 2
$arrPatch[4,$intCount] = "The operation completed successfully."
Case $intI = 3
$arrPatch[4,$intCount] = "The operation completed, but one or more errors occurred during the operation and the results are potentially incomplete."
Case $intI = 4
$arrPatch[4,$intCount] = "The operation failed to complete."
Case $intI = 5
$arrPatch[4,$intCount] = "The operation was aborted."
Case 1
$arrPatch[4,$intCount] = "Could not be determined."
EndSelect
$objIdentity = $objUpdate.UpdateIdentity
$arrPatch[5,$intCount] = $objIdentity.UpdateID
$intCount = $intCount + 1
ReDim Preserve $arrPatch[5,$intCount]
Next
$intCount = $intCount - 1
ReDim Preserve $arrPatch[5,$intCount]
$GetAllPatches = $arrPatch
EndFunction
Jooel, that was a typo. I have to retype everything from the system where I am testing. So, the above may also have a typo. I hope not. 
I called it as:
Break On
Dim $SO
;
$SO = SetOpt('Explicit', 'On')
$SO = SetOpt('NoMacrosInStrings', 'On')
;
Dim $strWks, $strComps, $colComps, $objComp, $arrPatches[5,0], $intI
;
$strComps = "u:\Desktop\computers.ini"
;
$colComps = Split(ReadProfileString($strComps,"computers",""),chr(10))
;
For Each $objComp in $colComps
If $objComp <> ""
$strWks - ReadProfileString($strComps,"computers",$objComp)
EndIf
$arrPatches = GetAllPatches($strWks)
Next
;
For $intI = 1 to Ubound($arrPatches,2)
? $arrPatches[0,0] + " : " + $arrPatches[0,$intI]
? $arrPatches[0,1] + " : " + $arrPatches[1,$intI]
? $arrPatches[0,2] + " : " + $arrPatches[2,$intI]
? $arrPatches[0,3] + " : " + $arrPatches[3,$intI]
? $arrPatches[0,4] + " : " + $arrPatches[4,$intI]
? $arrPatches[0,5] + " : " + $arrPatches[5,$intI]
? "----------------------------------------------------------------"
Next
Thanks so much for the help!!!!
Edited by BradV (2011-11-21 06:17 PM) Edit Reason: Modified to version 1.1
|