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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// 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"
// Exit macros
#define WuaExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__)
#define WuaExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__)
#define WuaExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__)
#define WuaExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__)
#define WuaExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__)
#define WuaExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__)
#define WuaExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_WUAUTIL, p, x, e, s, __VA_ARGS__)
#define WuaExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_WUAUTIL, p, x, s, __VA_ARGS__)
#define WuaExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_WUAUTIL, p, x, e, s, __VA_ARGS__)
#define WuaExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_WUAUTIL, p, x, s, __VA_ARGS__)
#define WuaExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_WUAUTIL, e, x, s, __VA_ARGS__)
#define WuaExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_WUAUTIL, g, x, s, __VA_ARGS__)
// 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);
WuaExitOnFailure(hr, "Failed to get the Automatic Updates service.");
hr = pAutomaticUpdates->Pause();
WuaExitOnFailure(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);
WuaExitOnFailure(hr, "Failed to get the Automatic Updates service.");
hr = pAutomaticUpdates->Resume();
WuaExitOnFailure(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));
WuaExitOnRootFailure(hr, "Failed to get WUA system information interface.");
hr = pSystemInformation->get_RebootRequired(&bRestartRequired);
WuaExitOnRootFailure(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);
WuaExitOnFailure(hr, "Failed to get CLSID for Microsoft.Update.AutoUpdate.");
hr = ::CoCreateInstance(clsidAutomaticUpdates, NULL, CLSCTX_INPROC_SERVER, IID_IAutomaticUpdates, reinterpret_cast<LPVOID*>(ppAutomaticUpdates));
WuaExitOnFailure(hr, "Failed to create instance of Microsoft.Update.AutoUpdate.");
LExit:
return hr;
}
|