potisanのプログラミングメモ

趣味のプログラマーがプログラミング関係で気になったことや調べたことをいつでも忘れられるようにメモするブログです。はてなブログ無料版なので記事の上の方はたぶん広告です。記事中にも広告挿入されるみたいです。

C++ WILとWindows Update Agent APIでWindows Update関連のシステム情報を取得する

WILとWindows Update Agent APIでSystemInformationを作成・管理してWUA API関連のシステム情報(OEMハードウェアサポートリンク、リブート要求)を取得するサンプルコードです。

#include <iostream>

#define STRICT
#define NOMINMAX
#include <Windows.h>
#include <wuapi.h>

#include <wil/com.h>
#include <wil/resource.h>

int main()
{
    auto couninit = wil::CoInitializeEx_failfast();

    auto systemInformation = wil::CoCreateInstanceFailFast<SystemInformation, ISystemInformation>();

    wil::unique_bstr oemHardwareSupportLink;
    VARIANT_BOOL rebootRequired;
    FAIL_FAST_IF_FAILED(systemInformation->get_OemHardwareSupportLink(&oemHardwareSupportLink));
    FAIL_FAST_IF_FAILED(systemInformation->get_RebootRequired(&rebootRequired));

    std::wcout << L"OEM Hardware Support Link: " << oemHardwareSupportLink.get() << std::endl;
    std::wcout << L"Reboot Required: " << std::boolalpha << !!rebootRequired << std::endl;

    return 0;
}

参考