Query from history is fast.#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <ole2.h>
#include <wuapi.h>
#pragma comment(lib, "ole32")
#pragma comment(lib, "oleaut32")
#pragma comment(lib, "msvcrt")
int printf(const char * format, ...);
const CLSID CLSID_UpdateSession={0x4CB43D7F,0x7EEE,0x4906,0x86,0x98,0x60,0xDA,0x1C,0x38,0xF2,0xFE};
const IID IID_IUpdateSession={0x816858A4,0x260D,0x4260,0x93,0x3A,0x25,0x85,0xF1,0xAB,0xC7,0x6B};
void ProcessList(ISearchResult* pResults);
void __cdecl mainCRTStartup(void)
{
HRESULT hr;
hr = CoInitialize(NULL);
IUpdateSession* pUpdate;
hr = CoCreateInstance(&CLSID_UpdateSession, NULL, CLSCTX_INPROC_SERVER, &IID_IUpdateSession, (LPVOID*)&pUpdate);
if (pUpdate)
{
IUpdateSearcher* pSearcher;
IUpdateHistoryEntryCollection* pHistory;
hr = pUpdate->lpVtbl->CreateUpdateSearcher(pUpdate, &pSearcher);
BSTR bstrCriteria = SysAllocString(L"IsInstalled=0");
printf("Searching updates...\n");
LONG nCount;
hr = pSearcher->lpVtbl->GetTotalHistoryCount(pSearcher, &nCount);
hr = pSearcher->lpVtbl->QueryHistory(pSearcher, 0, nCount, &pHistory);
SysFreeString(bstrCriteria);
if (pHistory) {
for (int i = 0; i< nCount; i++) {
IUpdateHistoryEntry* pEntry;
pHistory->lpVtbl->get_Item(pHistory, i, &pEntry );
if (pEntry) {
BSTR bstr;
pEntry->lpVtbl->get_Title(pEntry, &bstr);
DATE date;
SYSTEMTIME st;
pEntry->lpVtbl->get_Date(pEntry, &date);
VariantTimeToSystemTime(date, &st);
printf("%ls %d-%02d-%02d\n", bstr, st.wYear, st.wMonth, st.wDay);
SysFreeString(bstr);
pEntry->lpVtbl->Release(pEntry);
}
}
//ProcessList(pResults);
pHistory->lpVtbl->Release(pHistory);
}
pUpdate->lpVtbl->Release(pUpdate);
}
CoUninitialize();
ExitProcess(0);
}