Question

I'm writing a code to automatically download & install windows updates. (using "tlbimped" wuapi.dll and some sample code found over the Internet).

UpdateDownloader updateDownloader = Sesion.CreateUpdateDownloader();
updateDownloader.Updates = new UpdateCollection() { Item };                      
updateDownloader.BeginDownload(this, this, this);

And it's fine - i successfully can download and install update. But, i prefer to cache items, and do not download them if this item alredy exist in "special" folder. Google says, that i can use:

IUpdate.CopyFromCache(path, true);

But it doesn't work for me :(

Here is sample code

IUpdate Item { get; set; }
public UpdateSession Sesion { get; set; }

void CopyToFolder()
{
 string path=Environment.CurrentDirectory + @"\Updates";

 DirectoryInfo di = new  DirectoryInfo(path);

 if (!di.Exists) Directory.CreateDirectory(path);

 Item.CopyFromCache(path, true);
}

Item is not null, is downloaded. Can be installed, but can't be copied to the specified path.

Was it helpful?

Solution

Solution is quite easy - we should copy child (Bundled) updates instead of main (parent) one.

foreach (IUpdate child in Item.BundledUpdates)
{
   child.CopyFromCache(path, false);
}

This is exactly the answer as noted in the Remarks section of the IUpdate Interface page:

http://msdn.microsoft.com/en-us/library/aa386099(v=VS.85).aspx

"If the BundledUpdates property contains an IUpdateCollection, some properties and methods of the update may only be available on the bundled updates, for example, DownloadContents or CopyFromCache."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top