#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma hdrstop #pragma argsused using namespace std; #include #include int _tmain(int argc, _TCHAR* argv[]) { HRESULT hr; hr = CoInitialize(NULL); IUpdateSession* iUpdate; IUpdateSearcher* searcher; ISearchResult* results; BSTR criteria = SysAllocString(L"IsInstalled=0"); hr = CoCreateInstance(CLSID_UpdateSession, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateSession, (LPVOID*)&iUpdate); hr = iUpdate->CreateUpdateSearcher(&searcher); std::wcout.imbue(std::locale("korean")); std::wcout << L"업데이트를 찾고 있습니다 ..." << endl; hr = searcher->Search(criteria, &results); SysFreeString(criteria); switch (hr) { case S_OK: std::wcout << L"시스템에 적용 할 수있는 목록:" << endl; break; case WU_E_LEGACYSERVER: std::wcout << L"서버를 찾을수 없다" << endl; return 0; case WU_E_INVALID_CRITERIA: std::wcout << L"잘못된 검색 기준입니다." << endl; return 0; } IUpdateCollection* updateList; IUpdateCollection* bundledUpdates; IUpdate* updateItem; IUpdate* bundledUpdateItem; LONG updateSize; LONG bundledUpdateSize; BSTR updateName; BSTR severity; results->get_Updates(& updateList); updateList->get_Count(& updateSize); if (updateSize == 0) { std::wcout << L"업데이트 할수 있는 목록이 없습니다." << endl; } for (LONG i = 0; i < updateSize; i++) { updateList->get_Item(i, & updateItem); updateItem->get_Title(& updateName); severity = NULL; updateItem->get_MsrcSeverity(& severity); if (severity != NULL) { std::wcout << L"보안 업데이트: " << severity << endl; } std::wcout << i + 1 << " : " << updateName << endl; // bundled updates updateItem->get_BundledUpdates(& bundledUpdates); bundledUpdates->get_Count(& bundledUpdateSize); if (bundledUpdateSize != 0) { // iterate through bundled updates for (LONG ii = 0; ii < bundledUpdateSize; ii++) { bundledUpdates->get_Item(ii, & bundledUpdateItem); severity = NULL; bundledUpdateItem->get_MsrcSeverity(& severity); if (severity != NULL) { std::wcout << L" 번들 업데이트: " << severity << endl; } } } } ::CoUninitialize(); wcin.get(); return 0; }