/// <summary> /// lists the installed updates (still experimental) /// </summary> /// <returns>returns a list of installed updates</returns> public static List<UpdateOpInfo> listInstalledUpdatesFromHistory() { UpdateSession session = new UpdateSession(); IUpdateSearcher updateSearcher = session.CreateUpdateSearcher(); int count = updateSearcher.GetTotalHistoryCount(); IUpdateHistoryEntryCollection foundUpdates = updateSearcher.QueryHistory(0, count); HashSet<UpdateOpInfo> set = new HashSet<UpdateOpInfo>(); for (int i = 0; i < count; ++i) { var upd = foundUpdates[i]; UpdateOpInfo ud = new UpdateOpInfo(); ud.title = upd.Title; ud.ID = upd.UpdateIdentity.UpdateID; /* Note: The Date value seems to be in UTC and not in local * time, because this value was off by a few hours. */ ud.date = upd.Date; ud.operation = upd.Operation; ud.result = upd.ResultCode; //Check whether we have to add or remove the update. if (isInstallSuccess(upd)) set.Add(ud); else if (isUninstallSuccess(upd)) set.Remove(ud); upd = null; ud = null; } //for foundUpdates = null; updateSearcher = null; session = null; List<UpdateOpInfo> result = new List<UpdateOpInfo>(); foreach (var item in set) { result.Add(item); } set = null; return result; }
/// <summary> /// lists the update history /// </summary> /// <returns>returns the applied updates as list of UpdateOpInfo structures</returns> public static List<UpdateOpInfo> listUpdateHistory() { UpdateSession session = new UpdateSession(); IUpdateSearcher updateSearcher = session.CreateUpdateSearcher(); int count = updateSearcher.GetTotalHistoryCount(); var history = updateSearcher.QueryHistory(0, count); List<UpdateOpInfo> result = new List<UpdateOpInfo>(); for (int i = 0; i < count; ++i) { UpdateOpInfo opInfo = new UpdateOpInfo(); /* Note: The Date value seems to be in UTC and not in local * time, because this value was off by a few hours. */ opInfo.date = history[i].Date; opInfo.ID = history[i].UpdateIdentity.UpdateID; opInfo.operation = history[i].Operation; opInfo.result = history[i].ResultCode; opInfo.title = history[i].Title; result.Add(opInfo); } //for history = null; updateSearcher = null; session = null; return result; }