6

WindowsUpdatesMonitoringに関する情報を取得するためのサンプルコードを開発しています。Windows UpdateAgentAPIにぶつかりました。リンク: http: //msdn.microsoft.com/en-us/library/windows/desktop/aa387099 (v = vs.85).aspx

しかし、win32のAPIを見つけることができません。C#/。NETインターフェイスしか見つかりません。対応するwin32APIはありますか?

具体的には、Windows Update/Patchの「リリース日」を知りたいです。提案やガイダンスを楽しみにしています。

  • Srivathsa
4

1 に答える 1

15

WUA APIには、C ++アプリから使用できる一連のCOMインターフェイスが含まれているため、これらIUpdateSearcherIUpdateSessionおよびを試してくださいIUpdate

アップデートとリリース日を取得するこのサンプルc++アプリケーションを確認してください。

#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=1 or IsHidden=1 or IsPresent=1");

    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);

    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();
    wcin.get();
    return 0;
}
于 2012-10-18T15:47:17.857 に答える