我正在编写代码来自动下载和安装 Windows 更新。(使用“tlbimped”wuapi.dll 和一些在 Internet 上找到的示例代码)。
UpdateDownloader updateDownloader = Sesion.CreateUpdateDownloader();
updateDownloader.Updates = new UpdateCollection() { Item };
updateDownloader.BeginDownload(this, this, this);
很好 - 我可以成功下载并安装更新。但是,我更喜欢缓存项目,如果该项目已经存在于“特殊”文件夹中,则不要下载它们。谷歌说,我可以使用:
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);
}
项目不为空,已下载。可以安装,但不能复制到指定路径。