如何查询使用C#安装在计算机上的精确的和本地化的列表?<代码>E29
我将精确定义为匹配在Windows 7中程序和功能下的Microsoft视图安装更新对话框的"Microsoft“类别中显示的内容。
如果使用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);
}
} 发布于 2010-11-15 18:39:44
WUApi只注册通过WUApi完成的操作,因此如果手动安装或删除更新,它将在卸载后保留在列表中,或者永远不会出现在列表中。因此,在我看来,WUApi并不是一个准确的列表。
WMI允许访问精确的Windows更新列表,但该列表仅筛选为"Microsoft“类别。这很困难,因为我的要求是获得所有更新的列表。
在内部,“查看安装更新”对话框使用CBS (基于组件的服务)。不幸的是,CBS并不是公开的。有关API的一些详细信息可以在这里找到:http://msdn.microsoft.com/en-us/library/Aa903048.aspx
https://stackoverflow.com/questions/3525059
复制相似问题