在我的应用程序中,我将显示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更新“设置用于显示更新和在我的应用程序中使用相同的查询?
发布于 2020-03-31 14:14:54
解决方案是在标准中添加"IsAssigned=1“。
https://stackoverflow.com/questions/60951327
复制相似问题