static void GetWindowsUpdatesHistory(IUpdateSearcher uSearcher) { int count = uSearcher.GetTotalHistoryCount(); IUpdateHistoryEntryCollection collections = uSearcher.QueryHistory(0, count); UpdateIdsHistory = new List <Dictionary <string, string> >(); foreach (var item in collections) { try { IUpdateHistoryEntry2 historyEntry = (IUpdateHistoryEntry2)item; Dictionary <string, string> hu = new Dictionary <string, string>(); hu["Title"] = historyEntry.Title; hu["UpdateID"] = historyEntry.UpdateIdentity.UpdateID.ToString(); hu["RevisionNumber"] = historyEntry.UpdateIdentity.RevisionNumber.ToString(); //foreach (var item1 in hu) //Console.WriteLine(item1.Key + " : " + item1.Value); UpdateIdsHistory.Add(hu); } catch (Exception ex) { Console.WriteLine(ex); } //Console.WriteLine(); } }
public MsUpdate(IUpdateHistoryEntry2 update) { try { UUID = update.UpdateIdentity.UpdateID; Title = update.Title; Category = GetCategory(update.Categories); Description = update.Description; Date = update.Date; SupportUrl = update.SupportUrl; State = UpdateState.History; ResultCode = (int)update.ResultCode; HResult = update.HResult; } catch { } }
private void Load() { List <string> categoriesToExclude = Properties.Settings.Default.update_categories_to_exclude.Cast <string>().ToList().ConvertAll(x => x.ToLower().Trim()); UpdateSession session = new UpdateSession(); IUpdateSearcher searcher = session.CreateUpdateSearcher(); searcher.Online = false; //try //{ // ISearchResult result = searcher.Search("IsInstalled=1"); // foreach (IUpdate u in result.Updates) // { // var title = u.Title; // var kb = u.KBArticleIDs.Cast<string>().ToList().Aggregate( (x,y) => $"{x},{y}"); // var date = u.LastDeploymentChangeTime; // WindowsUpdatesData.Add(new WindowsUpdatesElement() // { // Date = date.ToString(), // Kb = kb, // Title = title // }); // } //} //catch { } var count = searcher.GetTotalHistoryCount(); if (count == 0) { return; } var history = searcher.QueryHistory(0, count); for (int i = 0; i < count; i++) { IUpdateHistoryEntry2 e = (IUpdateHistoryEntry2)history[i]; var category = "n/a"; ICategoryCollection categories = e.Categories; foreach (ICategory oc in categories) { category = oc.Name; break; } // check for excluded catgory if (categoriesToExclude.Contains(category.ToLower().Trim())) { continue; } var title = history[i].Title; IUpdateIdentity ident = history[i].UpdateIdentity; var id = ident.UpdateID; WindowsUpdatesData.Add(new WindowsUpdatesElement() { Kb = id, Title = title, Date = history[i].Date.ToString(), Result = history[i].ResultCode.ToString().Replace("orc", string.Empty), Category = category }); } }