Query for an accurate and localized list of installed Windows updates

How can I request an accurate and localized list of Windows updates installed on a machine using C #?

I precisely define what is displayed in the "Microsoft Windows" category in Microsoft View Installed Updates under "Programs and Features in Windows 7.

If I use WUApi.DLL, the information is returned localized, but I can not get the exact list. In the case of WUApi.dll, some fixes are missing, and if the update has been removed, it still appears in the list generated by the following code:

public static void GetWindowsUpdates() { var updateSession = new UpdateSession(); var updateSearcher = updateSession.CreateUpdateSearcher(); var count = updateSearcher.GetTotalHistoryCount(); if (count == 0) return; var history = updateSearcher.QueryHistory(0, count); for (int i = 0; i < count; i++) { if (history[i].ResultCode == OperationResultCode.orcSucceeded) { Console.WriteLine(history[i].Title); if (history[i].Operation == UpdateOperation.uoUninstallation) { Console.WriteLine("!!! Operation == uninstall"); // This is never true } } } } 

The WUApi search method also did not provide an exact list using the following code:

  WUApiLib.UpdateSessionClass session = new WUApiLib.UpdateSessionClass(); WUApiLib.IUpdateSearcher searcher = session.CreateUpdateSearcher(); searcher.IncludePotentiallySupersededUpdates = true; WUApiLib.ISearchResult result = searcher.Search("IsInstalled=1"); Console.WriteLine("Updates found: " + result.Updates.Count); foreach (IUpdate item in result.Updates) { Console.WriteLine(item.Title); } 

If I use WMI to read the list of updates, I can get the exact list, but it is not localized. I am using the following code:

 ManagementObjectSearcher searcher = new ManagementObjectSearcher(new ObjectQuery("select * from Win32_QuickFixEngineering")); searcher.Options.UseAmendedQualifiers = true; searcher.Scope.Options.Locale = "MS_" + CultureInfo.CurrentCulture.LCID.ToString("X"); ManagementObjectCollection results = searcher.Get(); Console.WriteLine("\n==WMI==" + results.Count); foreach (ManagementObject item in results) { Console.WriteLine("\t--Properties--"); foreach (var x in item.Properties) { Console.WriteLine(x.Name + ": " + item[x.Name]); } Console.WriteLine("\t--System Properties--"); foreach (var x in item.SystemProperties) { Console.WriteLine(x.Name + ": " + x.Value); } Console.WriteLine("\t--Qualifiers--"); foreach (var x in item.Qualifiers) { Console.WriteLine(x.Name + ": " + x.Value); } } 
+7
c # wmi
source share
1 answer

Only WUApi logs actions performed using WUApi, so if you manually install or remove the update, it will either remain in the list after it is uninstalled or will never appear in the list. As a result, in my opinion, WUApi cannot be counted on for an accurate list.

WMI allows you to access the exact list of Windows updates, but the list is filtered only in the "Microsoft Windows" category. This was difficult because my requirement was to get a list of all the updates.

The View Installed Updates dialog box internally uses CBS (Component Based Maintenance). Unfortunately, CBS is not public. Some API information can be found here: http://msdn.microsoft.com/en-us/library/Aa903048.aspx

+4
source share

All Articles