aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/wuautil.cpp
blob: 94ab659d6b91558fe926839013dda8035767e054 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

#include "precomp.h"


// internal function declarations

static HRESULT GetAutomaticUpdatesService(
    __out IAutomaticUpdates **ppAutomaticUpdates
    );


// function definitions

extern "C" HRESULT DAPI WuaPauseAutomaticUpdates()
{
    HRESULT hr = S_OK;
    IAutomaticUpdates *pAutomaticUpdates = NULL;

    hr = GetAutomaticUpdatesService(&pAutomaticUpdates);
    ExitOnFailure(hr, "Failed to get the Automatic Updates service.");

    hr = pAutomaticUpdates->Pause();
    ExitOnFailure(hr, "Failed to pause the Automatic Updates service.");

LExit:
    ReleaseObject(pAutomaticUpdates);

    return hr;
}

extern "C" HRESULT DAPI WuaResumeAutomaticUpdates()
{
    HRESULT hr = S_OK;
    IAutomaticUpdates *pAutomaticUpdates = NULL;

    hr = GetAutomaticUpdatesService(&pAutomaticUpdates);
    ExitOnFailure(hr, "Failed to get the Automatic Updates service.");

    hr = pAutomaticUpdates->Resume();
    ExitOnFailure(hr, "Failed to resume the Automatic Updates service.");

LExit:
    ReleaseObject(pAutomaticUpdates);

    return hr;
}

extern "C" HRESULT DAPI WuaRestartRequired(
    __out BOOL* pfRestartRequired
    )
{
    HRESULT hr = S_OK;
    ISystemInformation* pSystemInformation = NULL;
    VARIANT_BOOL bRestartRequired;

    hr = ::CoCreateInstance(__uuidof(SystemInformation), NULL, CLSCTX_INPROC_SERVER, __uuidof(ISystemInformation), reinterpret_cast<LPVOID*>(&pSystemInformation));
    ExitOnRootFailure(hr, "Failed to get WUA system information interface.");

    hr = pSystemInformation->get_RebootRequired(&bRestartRequired);
    ExitOnRootFailure(hr, "Failed to determine if restart is required from WUA.");

    *pfRestartRequired = (VARIANT_FALSE != bRestartRequired);

LExit:
    ReleaseObject(pSystemInformation);

    return hr;
}


// internal function definitions

static HRESULT GetAutomaticUpdatesService(
    __out IAutomaticUpdates **ppAutomaticUpdates
    )
{
    HRESULT hr = S_OK;
    CLSID clsidAutomaticUpdates = { };

    hr = ::CLSIDFromProgID(L"Microsoft.Update.AutoUpdate", &clsidAutomaticUpdates);
    ExitOnFailure(hr, "Failed to get CLSID for Microsoft.Update.AutoUpdate.");

    hr = ::CoCreateInstance(clsidAutomaticUpdates, NULL, CLSCTX_INPROC_SERVER, IID_IAutomaticUpdates, reinterpret_cast<LPVOID*>(ppAutomaticUpdates));
    ExitOnFailure(hr, "Failed to create instance of Microsoft.Update.AutoUpdate.");

LExit:
    return hr;
}