私はおそらく目が見えないだけですが、ここでエラーが表示されません(そして、私はすでにこの問題を数日間調べています...)
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 は、コントロール パネルの更新プログラムで確認できるように、更新プログラムを「重要」と「オプション」にどのように分類していますか?
ヒントをありがとう!// マーカス