- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我可能只是瞎了眼,但我在这里看不到任何错误(我已经研究这个问题好几天了......)
我正在尝试使用 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 现在如何将更新分类为“重要”和“可选”,就像您在控制面板的更新中看到的那样?
感谢您的任何提示!//马库斯
最佳答案
几个小时以来,我一直在为完全相同的问题而苦苦挣扎……我终于发现 Microsoft 似乎只在某些更新上设置了 MsrcSeverity 值。对于一般的 Windows 更新,它通常为空。对于大多数安全更新,它被设置为以下之一:
尽管在 MSDN ( http://msdn.microsoft.com/en-us/library/microsoft.updateservices.administration.msrcseverity(v=vs.85).aspx) 中有记录,但似乎从未使用过“Unspecified”值。
我编写了一个 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();
}
}
}
希望这对某人有帮助!
关于c++ - Visual C++,Windows 更新接口(interface) (IUpdate) <wuapi.h>,get_MsrcSeverity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22014098/
我可能只是瞎了眼,但我在这里看不到任何错误(我已经研究这个问题好几天了......) 我正在尝试使用 Visual Studio 中的以下代码从 Windows 更新界面获取补丁程序优先级(严重性):
我是一名优秀的程序员,十分优秀!