3

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.

Denis Olifer
  • 751
  • 1
  • 5
  • 20
  • 2
    Welcome to StackOverflow. "It doesn't work for me" is of no use. What exactly does that mean? Do you receive error messages? If so, what is the *exact* text of the message? Without that information, your question is very difficult to answer. Remember that we can't see your monitor from here, and most people's ESP isn't strong enough to work around the entire world. :) Please edit your question and add more information about the specific problem(s) you're having getting it to work so we can try and help you. – Ken White Aug 25 '11 at 23:02
  • Sorry about delay. "It doesn't work for me" means that method executed without any arrors. And also nothing happened. I see no files added into "path" directory. – Denis Olifer Aug 30 '11 at 09:37
  • @Ken White, sorry that i haven't provided detailed info. Now everything is better (I hope) – Denis Olifer Aug 30 '11 at 11:58

1 Answers1

2

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."

Community
  • 1
  • 1
Denis Olifer
  • 751
  • 1
  • 5
  • 20