Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 查询已安装Windows更新的准确本地化列表_C#_Wmi - Fatal编程技术网

C# 查询已安装Windows更新的准确本地化列表

C# 查询已安装Windows更新的准确本地化列表,c#,wmi,C#,Wmi,如何查询使用C#安装在计算机上的Windows更新的准确本地化列表? 我将“精确”定义为与Windows 7中“程序和功能”下“查看已安装更新”对话框的“Microsoft Windows”类别中显示的内容相匹配 如果我使用WUApi.DLL,则返回的信息是本地化的,但我无法获得准确的列表。在WUApi.dll的情况下,缺少一些修补程序,如果已卸载更新,它仍会显示在由以下代码生成的列表中: public static void GetWindowsUpdates() { var up

如何查询使用C#安装在计算机上的Windows更新的准确本地化列表?

我将“精确”定义为与Windows 7中“程序和功能”下“查看已安装更新”对话框的“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 
            } 
        } 
    } 
} 
        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); 
        } 
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); 
    } 
} 
如果我使用WMI读取更新列表,我可以得到一个准确的列表,但它不是本地化的。我使用以下代码:

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 
            } 
        } 
    } 
} 
        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); 
        } 
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”类别。这很困难,因为我的要求是获得所有更新的列表

在内部,“查看已安装的更新”对话框使用CBS(基于组件的服务)。不幸的是,哥伦比亚广播公司并不公开。有关API的一些详细信息可在此处找到:

在尝试获取所有更新时,我们面临相同的问题。你是如何解决这个问题的。如果可能的话,您可以分享代码吗?msdn上是否有关于“WUApi仅注册通过WUApi完成的操作”的文档?