首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Visual C++,Windows (IUpdate) <wuapi.h>,get_MsrcSeverity

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

Stack Overflow用户
提问于 2014-02-25 12:22:13
回答 2查看 2.1K关注 0票数 3

我可能只是瞎了眼,但我在这里看不到任何错误(我已经看了好几天了……)

我试图使用Visual中的以下代码从Windows Update接口获取修补程序优先级(严重性):

代码语言:javascript
复制
#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函数当前被破坏了?

@编辑:按照建议修改代码以遍历"BundledUpdates“。

@EDIT2 2:代码现在输出updateItembundledUpdatesItem的严重性值,但始终是NULL

我也知道有一个重要的更新在等待我的计算机-有关Windows更新在控制面板。是KB2858725。

@EDIT3 3:好的,事实证明,KB2858725不是安全更新,因此没有微软的严重级别。但是,Microsoft Windows update现在如何将更新划分为“重要”和“可选”,就像您在控制面板的更新中看到的那样?

谢谢你的暗示!//马库斯

EN

回答 2

Stack Overflow用户

发布于 2014-06-25 21:30:03

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

  • “批判”
  • “温和”
  • “重要”
  • “低”

尽管MSDN (http://msdn.microsoft.com/en-us/library/microsoft.updateservices.administration.msrcseverity(v=vs.85).aspx)中记录了“未指定”值,但它似乎从未被使用过。

我编写了一个小型C#程序来列出所有可用的更新及其报告的严重性。它需要引用WUApiLib:

代码语言:javascript
复制
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();
        }
    }
}

希望这能帮到别人!

票数 3
EN

Stack Overflow用户

发布于 2014-02-25 12:24:08

查找列表中的捆绑更新。捆绑更新不具有页面中描述的某些属性或方法。

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

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

IUpdate接口有一个方法get_BundledUpdates,如果这个集合的大小大于0,它将为您提供一个IUpdateCollection,这是一个捆绑更新。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22014098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档