我可能只是盲人,但我在这里看不到任何错误(而且我已经在这个问题上找了好几天了......)
我正在尝试使用 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:代码现在输出 和 的严重性值updateItem
,bundledUpdatesItem
但它始终是NULL
。
我也知道有一个重要的更新正在等待我的计算机 - 关于控制面板中的 Windows 更新。它是 KB2858725。
@EDIT3:好的,事实证明,KB2858725 不是安全更新,因此没有 Microsoft 的严重性评级。但是,Microsoft Windows Update 现在如何将更新分类为“重要”和“可选”,就像您在控制面板的更新中看到的那样?
感谢您的任何提示!// 马库斯