我想获取 windows 更新补丁的下载 url,我的代码是
var session = new UpdateSession();
var searcher = session.CreateUpdateSearcher();
var searchType = "Type='Software' and IsInstalled =0";
searcher.Online = false;
var searchResult = searcher.Search(searchType);
var collection = searchResult.Updates;
foreach (IUpdate item in collection)
{
outpu("Title: \t{0}", item.Title);
outpu("UpdateId: \t{0}", item.Identity.UpdateID);
outpu("Description: \t{0}", item.Description);
if (item.KBArticleIDs[0] == "2592687")
{
Trace.WriteLine("what");
}
if ((item.BundledUpdates.Count > 0) && (item.BundledUpdates[0].DownloadContents.Count >0))
outpu("DownloadUrl: \t{0}", item.BundledUpdates[0].DownloadContents[0].DownloadUrl);
}
通常我可以得到下载网址,但有时我不能。例如,当
KBArticleIDs = "2592687"
调试显示“DownloadContents”没有孩子,我该怎么办?