【问题标题】:Get Windows System updates using wuapi使用 wuapi 获取 Windows 系统更新
【发布时间】:2020-03-31 22:14:54
【问题描述】:

在我的应用程序中,我显示 Windows 机器是否有可用的更新,这些更新应该与“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 and IsHidden=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);

    //...
}

我的问题是,在某些机器上,此代码给出的结果是有可用的更新,但在“Windows 更新”设置页面中没有。我检查了日志,有一些更新被标记为“不完整/无效”,因此没有显示在“Windows 更新”设置页面中,但是这段代码出于某种原因得到了它们。我认为问题在于使用了不正确的搜索查询。也许
"IsInstalled=0 and IsHidden=0" 还不够。是否可以确切地知道“Windows 更新”设置使用什么查询来显示更新并在我的应用程序中使用相同的查询?

【问题讨论】:

    标签: c++ windows winapi windows-update


    【解决方案1】:

    解决方案是在条件中添加“IsAssigned=1”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-16
      • 2011-11-07
      相关资源
      最近更新 更多