我正在编写代码来自动下载和安装 Windows 更新。 (使用“tlbimped”wuapi.dll 和在 Internet 上找到的一些示例代码)。
UpdateDownloader updateDownloader = Sesion.CreateUpdateDownloader();
updateDownloader.Updates = new UpdateCollection() { Item };
updateDownloader.BeginDownload(this, this, this);
没关系 - 我可以成功下载并安装更新。但是,我更喜欢缓存项目,如果该项目已经存在于“特殊”文件夹中,则不要下载它们。 Google 说,我可以使用:
IUpdate.CopyFromCache(path, true);
但这对我不起作用:(
这里是示例代码
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);
}
项目不为空,已下载。可以安装,但不能复制到指定路径。
最佳答案
解决方案非常简单 - 我们应该复制子(捆绑)更新而不是主(父)更新。
foreach (IUpdate child in Item.BundledUpdates)
{
child.CopyFromCache(path, false);
}
这正是 IUpdate 界面页面的备注部分中指出的答案:
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."
关于c# - Windows 更新 API c# : set download location,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7197182/