"Microsoft.Update.Session question

Started by stanl, June 17, 2019, 01:29:19 PM

Previous topic - Next topic

stanl

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
;=====================================================================================



td

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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

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

td

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
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade