c# – 查询已安装的Windows更新的准确和本地化列表
发布时间:2020-12-15 08:00:41 所属栏目:百科 来源:网络整理
导读:如何使用C#查询安装在计算机上的 Windows更新的准确和本地化列表? 我将精确定义为匹配Windows 7中“程序和功能”下Microsoft的“View Installed Updates”对话框的“Microsoft Windows”类别中显示的内容. 如果我使用WUApi.DLL,信息将被返回本地化但我无法
如何使用C#查询安装在计算机上的
Windows更新的准确和本地化列表?
我将精确定义为匹配Windows 7中“程序和功能”下Microsoft的“View Installed Updates”对话框的“Microsoft Windows”类别中显示的内容. 如果我使用WUApi.DLL,信息将被返回本地化但我无法获得准确的列表.在WUApi.dll的情况下,一些修补程序丢失,如果已卸载更新,它仍会显示在由以下代码生成的列表中: 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 } } } } WUApi搜索方法也没有使用以下代码提供准确的列表: 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); } 如果我使用WMI来读取更新列表,我可以获得准确的列表,但它没有本地化.我使用以下代码: 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); } } 解决方法
WUApi只注册通过WUApi完成的操作,因此如果您手动安装或删除更新,它将在卸载后保留在列表中,或者永远不会显示在列表中.因此,在我看来,WUApi不能指望准确的清单.
WMI允许访问准确的Windows更新列表,但该列表仅过滤为“Microsoft Windows”类别.这很困难,因为我的要求是获取所有更新的列表. 在“View Installed Updates”对话框内部使用CBS(基于组件的服务).不幸的是,CBS不公开.有关API的一些详细信息,请访问: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |