在我的应用程序中,我显示 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 和 IsHidden=0”
还不够。是否可以准确地知道“Windows 更新”设置使用什么查询来显示更新并在我的应用程序中使用相同的查询?
最佳答案
解决方案是将“IsAssigned=1”添加到条件中。
关于c++ - 使用 wuapi 获取 Windows 系统更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60951327/