确定Windows Update分类 [英] Determine Windows Update classification

查看:69
本文介绍了确定Windows Update分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Windows Update COM库(WUAPILib),我可以访问

From the Windows Update COM Library (WUAPILib) I have access to the IUpdate interface however I don't see of any way to use to get the update classification (Critical, Important, Optional) to group updates in the same way like the Windows Update UI in Control Panel does.

解决方案

With the help of the IUpdate, you can get the IcategoryCollection from the Update ID.

Now, the first ICategory stores the classification of update type for the OS. Do pay special attention to the line where comment is placed:

Console.WriteLine("Patch name = " + ic.Name.ToString());
// In the ICategory collection, first element ICategory stores information of "Update Classification"; 
// whereas second Icategory element stores the product type information.

Test Code:

UpdateSession uSession = new UpdateSession();
IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
uSearcher.Online = false;
ISearchResult sResult = uSearcher.Search("IsInstalled=1 And IsHidden=0");
Console.WriteLine("Found " + sResult.Updates.Count + " updates" + Environment.NewLine);
   foreach (IUpdate update in sResult.Updates)
   {
          Console.WriteLine();
          Console.WriteLine("Required update " + update.KBArticleIDs[0].ToString() + " is installed...");
          Console.WriteLine("Update ID = "+update.Identity.UpdateID);
          ICategoryCollection icc = update.Categories;
          foreach (ICategory ic in icc)
          {
            Console.WriteLine("Patch description = " + ic.Description.ToString());
            Console.WriteLine("Patch category = " + ic.CategoryID.ToString());
            Console.WriteLine("Patch Type = " + ic.Type.ToString());
            Console.WriteLine("Patch name = " + ic.Name.ToString()); 
// only first ICategory element stores the patch name,
// which reveals the Classification information
          }
   }

Sample Output:

这篇关于确定Windows Update分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆