我想获取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"
debug显示“DownloadContents”没有子节点,那我该怎么办?