3

私はおそらく目が見えないだけですが、ここでエラーが表示されません(そして、私はすでにこの問題を数日間調べています...)

Visual Studio で次のコードを使用して、Windows Update インターフェイスからパッチの優先度 (重大度) を取得しようとしています。

#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: コードは と の重大度の値を出力するupdateItemようになりましたbundledUpdatesItemが、常にNULLです。

また、コントロール パネルの Windows Update に関する重要な更新プログラムが 1 つあることも知っています。KB2858725です。

@EDIT3: わかりました。KB2858725 はセキュリティ更新プログラムではないため、Microsoft による深刻度の評価はありません。しかし、Microsoft Windows Update は、コントロール パネルの更新プログラムで確認できるように、更新プログラムを「重要」と「オプション」にどのように分類していますか?

ヒントをありがとう!// マーカス

4

2 に答える 2

1

リストでバンドルされた更新を探します。バンドルされた更新プログラムには、このページで説明されている一部のプロパティまたはメソッドがありません。

備考

BundledUpdates プロパティに IUpdateCollection が含まれている場合、更新プログラムの一部のプロパティとメソッドは、バンドルされた更新プログラムでのみ使用できる場合があります (DownloadContents や CopyFromCache など)。

処理中の更新は、バンドルされた更新です。このバンドルから個々の更新を抽出すると、探しているプロパティが含まれます。

IUpdateインターフェイスには、このコレクションのサイズが 0 より大きい場合に取得するメソッドがあります。これはバンドルされた更新ですget_BundledUpdatesIUpdateCollection

于 2014-02-25T12:24:08.550 に答える