【问题标题】:Windows Update Agent pure win32 APIsWindows 更新代理纯 win32 API
【发布时间】:2012-10-08 13:53:20
【问题描述】:

我正在开发一个示例代码来获取有关 Windows 更新监控的信息。 我碰到了 Windows 更新代理 API。链接:http://msdn.microsoft.com/en-us/library/windows/desktop/aa387099(v=vs.85).aspx

但我找不到任何适用于 win32 的 API。我发现只有 C#/.NET 接口。 有没有对应的win32 API?

具体来说,我想找出 Windows 更新/补丁的“发布日期”。 期待任何建议和指导。

  • 斯里瓦萨

【问题讨论】:

  • 发布的链接不包含 C#/.NET 特定的代码。它几乎都是关于 COM 的,所以你也可以在 C/C++ 中使用它。
  • 哦,好的。将探索更多。我对COM知之甚少。谢谢。

标签: c++ winapi windows-update


【解决方案1】:

WUA API 包含一组可从 C++ 应用程序使用的 COM 接口,因此请尝试这些IUpdateSearcherIUpdateSessionIUpdate

查看此示例 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;
}

【讨论】:

  • 感谢 RRUZ。会试试这个。我将尝试获得一点 COM 知识。
猜你喜欢
  • 2015-03-20
  • 1970-01-01
  • 2011-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 1970-01-01
  • 2015-02-04
相关资源
最近更新 更多