Visual C++, Windows Update Interface (IUpdate) <wuapi.h>, get_MsrcSeverity



我可能只是失明,但我在这里看不到任何错误(我已经关注这个问题好几天了…)

我正试图在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:代码现在输出updateItembundledUpdatesItem的严重性值,但它始终是NULL

我还知道有一个重要的更新正在等待我的电脑——关于控制面板中的Windows update。它是KB2858725。

@第三版:好吧,事实证明,KB2858725没有安全更新,因此微软没有对其进行严重性评级。但是,Microsoft Windows Update现在如何将更新分为"重要"one_answers"可选",就像你在控制面板的更新中看到的那样?

谢谢你的提示!//Markus

我已经为同样的问题挣扎了几个小时了。。。我终于发现,Microsoft似乎只在某些更新中设置MsrcSeverity值。对于一般的Windows更新,它通常为null。对于大多数安全更新,它被设置为以下之一:

  • "关键">
  • "中等">
  • "重要">
  • "低">

尽管MSDN中记录了"Unspecified"值,但它似乎从未使用过(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();
}
}
}

希望这能帮助到别人!

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

备注

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

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

IUpdate接口有一个方法get_BundledUpdates,如果此集合的大小大于0,则会获得一个IUpdateCollection,这是一个绑定更新。

最新更新