Open SSubZero opened 9 years ago
From further discussion in IRC:
I'll see what I can do in the next few days.
Well, I've been doing some research and so far it doesn't look good.
I access WU via the Windows Update Agent API which is a set of COM interfaces.
WUA exposes the IUpdateDownloader interface for downloading updates. With this we can user the Download to download all pending update synchronously. That's what the script does now.
But this method's drawback is that it downloads them all as one big lump, tying up the script until it is done. It doesn't emit any status. So there's no data to base a status bar on. I could display a spinning bar or something but it would be totally fake: if the download job hung, the spinbar would just spin forever.
I experimented with telling the IUpdateDownloader to get only one of the available updates, print the update's KBID number, then go download the next one. This allowed the script to report progress more frequently, but it made the overall download take almost twice as long.
IUpdateDownloader has an asynchronous BeginDownload method which would emit status at regular intervals, but alas, PowerShell currently has no way to subscribe to asynchronous COM object methods. (Well, I didn't find one, anyway.)
The IUpdateInstaller works basically the same way as the downloader works. Synchronous does it all in one lump without status; asynchronous emits status as it goes but is not accessible from PowerShell.
All of this has baked my noodle! I'll keep thinking on it, and ask a couple of PS gurus I know. You can call Install-Update with the -Verbose parameter, which will give you a tiny bit more output, but for now I think that is as good as it gets.
It may be possible to put this technique to use: http://goo.gl/TUsFd3, http://goo.gl/QwcT3S
Stick the IUpdateDownloader.download and IUpdateinstaller.install jobs in their own threads, then check the $updatelist object from time to time. Man I wish there was a .NET interface to WUA!
I'll fiddle with that sometime soon.
from IRC:
S_SubZero: mota: yeah, the actual update info is not important, just something spinning or
otherwise "still going"
S_SubZero: they used to make that spinny thing with \ / - | 8)
May take another run at using the async methods of IUpdateDownloader and Installer.. https://msdn.microsoft.com/en-us/library/windows/desktop/aa386132(v=vs.85).aspx
This guy has async with progress indication working ... in vbscript. https://github.com/vattay/WuF
Would be good if it had some rudimentary way to track progress or to at least indicate activity.