C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 팁&트릭
C++Builder Programming Tip&Tricks
[1167] 윈도우 업데이트 체크 (WUA API)
사탄 [kdhs] 9210 읽음    2015-11-13 09:53
자료를 찾다보니 포럼에는 없는거 같아 만들어본 소스를 올려봅니다.

API를 보면 다운로드 설치까지 가능하지만 저는 업데이트 유/무 이 정도만 필요했어서....

그럼 아래에 코드를 보시면 되겠습니다.


#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;
}


+ -

관련 글 리스트
1167 윈도우 업데이트 체크 (WUA API) 사탄 9210 2015/11/13
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.