This repository has been archived by the owner on Jan 6, 2020. It is now read-only.
forked from cavaliercoder/sysinv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hotfixes.cpp
executable file
·72 lines (59 loc) · 1.9 KB
/
hotfixes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "stdafx.h"
#include <wuapi.h>
#include <iostream>
#include <ATLComTime.h>
#include <wuerror.h>
using namespace std;
// Product Behavior: http://msdn.microsoft.com/en-us/library/ee917276.aspx
// Delphi example: http://theroadtodelphi.wordpress.com/2011/03/02/search-for-installed-windows-updates-using-delphi-wmi-and-wua/
int HotFixTest()
{
HRESULT hr;
hr = CoInitialize(NULL);
IUpdateSession* iUpdate;
IUpdateSearcher* searcher;
ISearchResult* results;
BSTR criteria = SysAllocString(L"IsInstalled=1 or IsHidden=1 or IsPresent=1"); // or IsHidden=1 or IsPresent=1
hr = CoCreateInstance(CLSID_UpdateSession, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateSession, (LPVOID*)&iUpdate);
hr = iUpdate->CreateUpdateSearcher(&searcher);
// Searcher options
searcher->put_IncludePotentiallySupersededUpdates(false);
searcher->put_Online(false);
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;
IUpdate *updateItem;
LONG updateSize;
BSTR updateName;
DATE retdate;
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);
updateItem->get_LastDeploymentChangeTime(&retdate);
COleDateTime odt;
odt.m_dt = retdate;
wcout << i + 1 << " - " << updateName << " Release Date " << (LPCTSTR)odt.Format(_T("%A, %B %d, %Y")) << endl;
}
::CoUninitialize();
return 0;
}