WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: stanl on June 17, 2019, 01:29:19 PM

Title: "Microsoft.Update.Session question
Post by: stanl on June 17, 2019, 01:29:19 PM
Just playing around and the output is ugly.... but trying to get the count of the historycount() prior to any display.
Code (WINBATCH) Select


;Winbatch 2019 - working with Windows Updates
;Stan Littlefield, June 17, 2019
;=====================================================================================
oSession   = CreateObject("Microsoft.Update.Session")
oSearcher  = oSession.CreateUpdateSearcher()
oHistory   = oSearcher.GetTotalHistoryCount()
results    = oSearcher.QueryHistory(1,oHistory)


filter = "SQL Server"
ForEach r in results
  If StrIndexNC(r.Title,filter,0,@FWDSCAN)
     txt = r.Date:@LF:r.Title:@LF:r.Description:@LF:r.SupportUrl
     Display(2,"Update Results:",txt)
  Endif
Next




oHistory  =0
oSearcher =0
oSession  =0
Exit
;=====================================================================================


Title: Re: "Microsoft.Update.Session question
Post by: td on June 17, 2019, 02:56:37 PM
I may be completely missing the point of your question but the GetTotalHistoryCount() "Getter" method returns an integer and not an object.  If you run your script in the WinBatch Studio debugger, you will notice that the data type of your "oHistory" object is "VT i4" which is COM Automation speak for a 4 byte integer.
Title: Re: "Microsoft.Update.Session question
Post by: stanl on June 18, 2019, 03:06:14 AM
Quote from: td on June 17, 2019, 02:56:37 PM
I may be completely missing the point of your question but the GetTotalHistoryCount() "Getter" method returns an integer and not an object.  If you run your script in the WinBatch Studio debugger, you will notice that the data type of your "oHistory" object is "VT i4" which is COM Automation speak for a 4 byte integer.


Yeah. Totally screwed the question up. Wanted to get the count of the filter, i.e. number of updates with "SQL Server". But, while on the subject, want to confirm:

oSearcher.QueryHistory(0,1) ; latest update


oSearcher.QueryHistory(oHistory-1,1) ; earliest update
Title: Re: "Microsoft.Update.Session question
Post by: td on June 18, 2019, 07:37:14 AM
MSFT doesn't bother to mention exactly what QueryHistory's startIndex parameter means so a little trial and error might be necessary.

https://docs.microsoft.com/en-us/windows/desktop/api/wuapi/nf-wuapi-iupdatesearcher-queryhistory (https://docs.microsoft.com/en-us/windows/desktop/api/wuapi/nf-wuapi-iupdatesearcher-queryhistory)