c# - Windows 更新 API c# : set download location

标签 c# .net windows hotfix

我正在编写代码来自动下载和安装 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/

相关文章:

c# - 我的 dotnet 应用程序不能在 Windows Server 2003 上运行

c# - 在缩放模式 Picturebox 中平移矩形位置会导致负 Y 坐标

c# - 如何向 CryptoStream 添加查找和定位功能

c# - 如何从目录中获取文件名,而不是整个路径

c++ - 搜索.exe的路径

windows - Windows : VBScript, JScript, Wscript 选哪个

c# - 在 Visual Studio 2017 中向 Xamarin.Forms 应用程序添加新内容页面时出错

c# - 如何使用 Control.DrawToBitmap 将 Form 渲染为没有装饰(标题栏、边框)的 Bitmap?

c# - 在不使用接口(interface)的情况下访问 F# 记录基本属性

c++ - HKEY 句柄为 NULL,在调试期间它写入未使用的<无法读取内存>