viewpoint-particle

Author Topic: "Microsoft.Update.Session question  (Read 221 times)

stanl

  • Pundit
  • *****
  • Posts: 951
"Microsoft.Update.Session question
« 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

;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

  • Tech Support
  • *****
  • Posts: 3103
    • WinBatch
Re: "Microsoft.Update.Session question
« Reply #1 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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

  • Pundit
  • *****
  • Posts: 951
Re: "Microsoft.Update.Session question
« Reply #2 on: June 18, 2019, 03:06:14 am »
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

  • Tech Support
  • *****
  • Posts: 3103
    • WinBatch
Re: "Microsoft.Update.Session question
« Reply #3 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
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade