确定Windows 更新分类
Determine Windows Update classification
从 Windows 更新 COM 库 (WUAPILib) 我可以访问 IUpdate 界面,但是我看不到任何方法来获取更新分类(关键、重要、可选)以与控制面板中的 Windows 更新 UI 相同的方式对更新进行分组。
借助 IUpdate,您可以从更新 ID 中获取 IcategoryCollection。
现在,第一个 ICategory 存储 OS 的更新类型分类。请特别注意放置评论的行:
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.
测试代码:
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
}
}
示例输出:
从 Windows 更新 COM 库 (WUAPILib) 我可以访问 IUpdate 界面,但是我看不到任何方法来获取更新分类(关键、重要、可选)以与控制面板中的 Windows 更新 UI 相同的方式对更新进行分组。
借助 IUpdate,您可以从更新 ID 中获取 IcategoryCollection。
现在,第一个 ICategory 存储 OS 的更新类型分类。请特别注意放置评论的行:
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.
测试代码:
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
}
}
示例输出: