本文介绍了Windows Update代理纯win32 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个示例代码以获取有关Windows更新监视的信息。
我碰到了Windows Update代理API。链接:

I'm developing a sample code to get information about the Windows Updates Monitoring.I bumped into Windows Update Agent APIs. link: http://msdn.microsoft.com/en-us/library/windows/desktop/aa387099(v=vs.85).aspx

但我无法找到任何用于win32的API。我只找到C#/。NET接口。
是否有相应的win32 API?

But I'm not able to find any APIs for win32. I find only C#/.NET Interfaces.Are there any corresponding win32 APIs?

具体来说,我想了解一下windows更新/补丁的发布日期。
期待任何建议和指导。

Specifically I want to find out the "release date" of a windows update/patch.Look forward to any suggestions and guidance.


  • Srivathsa

推荐答案

包括一组可以从C ++应用程序使用的COM接口,因此请尝试这些,和 。

The WUA API includes a set of COM interfaces which can be used from C++ Apps, so try these IUpdateSearcher, IUpdateSession and IUpdate.

检查此示例c ++应用程序,检索更新和发布日期。

Check this sample c++ application which retrieve the updates and the date of release.

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

这篇关于Windows Update代理纯win32 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 09:38