3

我可能只是盲人,但我在这里看不到任何错误(而且我已经在这个问题上找了好几天了......)

我正在尝试使用 Visual Studio 中的以下代码从 Windows 更新界面获取补丁优先级(严重性):

#include "stdafx.h"
#include <wuapi.h>
#include <iostream>
#include <ATLComTime.h>
#include <wuerror.h>

using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{


     HRESULT hr;
    hr = CoInitialize(NULL);

    IUpdateSession* iUpdate;
    IUpdateSearcher* searcher;
    ISearchResult* results;
    BSTR criteria = SysAllocString(L"IsInstalled=0");

    hr = CoCreateInstance(CLSID_UpdateSession, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateSession, (LPVOID*)&iUpdate);
    hr = iUpdate->CreateUpdateSearcher(&searcher);

    wcout << L"Searching for updates ..."<<endl;
    hr = searcher->Search(criteria, &results); 
    SysFreeString(criteria);

    switch(hr)
    {
    case S_OK:
        wcout<<L"List of applicable items on the machine:"<<endl;
        break;
    case WU_E_LEGACYSERVER:
        wcout<<L"No server selection enabled"<<endl;
        return 0;
    case WU_E_INVALID_CRITERIA:
        wcout<<L"Invalid search criteria"<<endl;
        return 0;
    }

    IUpdateCollection *updateList;
    IUpdateCollection *bundledUpdates;
    IUpdate *updateItem;
    IUpdate *bundledUpdateItem;
    LONG updateSize;
    LONG bundledUpdateSize;
    BSTR updateName;
    BSTR severity;

    results->get_Updates(&updateList);
    updateList->get_Count(&updateSize);

    if (updateSize == 0)
    {
        wcout << L"No updates found"<<endl;
    }

    for (LONG i = 0; i < updateSize; i++)
    {
        updateList->get_Item(i,&updateItem);
        updateItem->get_Title(&updateName);

        severity = NULL;
        updateItem->get_MsrcSeverity(&severity);
        if (severity != NULL) 
        {
            wcout << L"update severity: " << severity << endl;
        }

        wcout<<i+1<<" - " << updateName << endl;

        // bundled updates
        updateItem->get_BundledUpdates(&bundledUpdates);
        bundledUpdates->get_Count(&bundledUpdateSize);

        if (bundledUpdateSize != 0) 
        {
            // iterate through bundled updates
            for (LONG ii = 0; ii < bundledUpdateSize; ii++) 
            {
                bundledUpdates->get_Item(ii, &bundledUpdateItem);
                severity = NULL;
                bundledUpdateItem->get_MsrcSeverity(&severity);
                if (severity != NULL) 
                {
                    wcout << L" bundled update severity: " << severity << endl;
                }
            }

        }

    }

    ::CoUninitialize();
    wcin.get();


    return 0;
}

所以这里的问题updateItem->get_MsrcSeverity(&severity);是:没有返回任何东西。如果我用它捕获结果代码,HRESULT它总是返回S_OK.

链接到 MSDN IUpdate MsrcSeverity:http: //msdn.microsoft.com/en-us/library/windows/desktop/aa386906 (v=vs.85).aspx

你能看出我在做什么明显错了,还是这个get_MsrcSeverity功能目前被破坏了?

@EDIT:更改了代码以按照建议遍历“BundledUpdates”。

@EDIT2:代码现在输出 和 的严重性值updateItembundledUpdatesItem但它始终是NULL

我也知道有一个重要的更新正在等待我的计算机 - 关于控制面板中的 Windows 更新。它是 KB2858725。

@EDIT3:好的,事实证明,KB2858725 不是安全更新,因此没有 Microsoft 的严重性评级。但是,Microsoft Windows Update 现在如何将更新分类为“重要”和“可选”,就像您在控制面板的更新中看到的那样?

感谢您的任何提示!// 马库斯

4

2 回答 2

3

几个小时以来,我一直在为同样的问题苦苦挣扎……我终于发现微软似乎只在某些更新上设置了 MsrcSeverity 值。对于一般的 Windows 更新,它通常为空。对于大多数安全更新,它设置为以下之一:

  • “批判的”
  • “缓和”
  • “重要的”
  • “低的”

似乎从未使用过“未指定”值,尽管它记录在 MSDN ( http://msdn.microsoft.com/en-us/library/microsoft.updateservices.administration.msrcseverity(v=vs.85) .aspx)。

我编写了一个小型 C# 程序来列出所有可用的更新及其报告的严重性。它需要对 WUApiLib 的引用:

using System;
using WUApiLib;

namespace EnumerateUpdates
{
    class Program
    {
        static void Main(string[] args)
        {
            var session = new UpdateSession();
            var searcher = session.CreateUpdateSearcher();
            searcher.Online = false;

            // Find all updates that have not yet been installed
            var result = searcher.Search("IsInstalled=0 And IsHidden=0");
            foreach (dynamic update in result.Updates)
            {
                Console.WriteLine(update.Title + ": " + update.Description);
                Console.WriteLine("Severity is " + update.MsrcSeverity);
                Console.WriteLine();
            }

            Console.ReadLine();
        }
    }
}

希望这对某人有帮助!

于 2014-06-25T21:30:03.013 回答
1

在列表中查找捆绑的更新。捆绑更新没有本页所述的某些属性或方法

评论

如果 BundledUpdates 属性包含 IUpdateCollection,则更新的某些属性和方法可能仅在捆绑更新上可用,例如,DownloadContents 或 CopyFromCache。

您正在处理的更新是捆绑更新。从此包中提取单个更新,它将具有您正在寻找的属性。

IUpdate接口有一个方法,如果此集合的大小大于 0,则为get_BundledUpdates您提供一个方法,这是一个捆绑更新。IUpdateCollection

于 2014-02-25T12:24:08.550 回答