diff options
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/wuautil.cpp')
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/wuautil.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/wuautil.cpp b/src/libs/dutil/WixToolset.DUtil/wuautil.cpp new file mode 100644 index 00000000..dfb28818 --- /dev/null +++ b/src/libs/dutil/WixToolset.DUtil/wuautil.cpp | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | #include "precomp.h" | ||
| 4 | |||
| 5 | |||
| 6 | // Exit macros | ||
| 7 | #define WuaExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__) | ||
| 8 | #define WuaExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__) | ||
| 9 | #define WuaExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__) | ||
| 10 | #define WuaExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__) | ||
| 11 | #define WuaExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__) | ||
| 12 | #define WuaExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__) | ||
| 13 | #define WuaExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_WUAUTIL, p, x, e, s, __VA_ARGS__) | ||
| 14 | #define WuaExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_WUAUTIL, p, x, s, __VA_ARGS__) | ||
| 15 | #define WuaExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_WUAUTIL, p, x, e, s, __VA_ARGS__) | ||
| 16 | #define WuaExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_WUAUTIL, p, x, s, __VA_ARGS__) | ||
| 17 | #define WuaExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_WUAUTIL, e, x, s, __VA_ARGS__) | ||
| 18 | #define WuaExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_WUAUTIL, g, x, s, __VA_ARGS__) | ||
| 19 | |||
| 20 | |||
| 21 | // internal function declarations | ||
| 22 | |||
| 23 | static HRESULT GetAutomaticUpdatesService( | ||
| 24 | __out IAutomaticUpdates **ppAutomaticUpdates | ||
| 25 | ); | ||
| 26 | |||
| 27 | |||
| 28 | // function definitions | ||
| 29 | |||
| 30 | extern "C" HRESULT DAPI WuaPauseAutomaticUpdates() | ||
| 31 | { | ||
| 32 | HRESULT hr = S_OK; | ||
| 33 | IAutomaticUpdates *pAutomaticUpdates = NULL; | ||
| 34 | |||
| 35 | hr = GetAutomaticUpdatesService(&pAutomaticUpdates); | ||
| 36 | WuaExitOnFailure(hr, "Failed to get the Automatic Updates service."); | ||
| 37 | |||
| 38 | hr = pAutomaticUpdates->Pause(); | ||
| 39 | WuaExitOnFailure(hr, "Failed to pause the Automatic Updates service."); | ||
| 40 | |||
| 41 | LExit: | ||
| 42 | ReleaseObject(pAutomaticUpdates); | ||
| 43 | |||
| 44 | return hr; | ||
| 45 | } | ||
| 46 | |||
| 47 | extern "C" HRESULT DAPI WuaResumeAutomaticUpdates() | ||
| 48 | { | ||
| 49 | HRESULT hr = S_OK; | ||
| 50 | IAutomaticUpdates *pAutomaticUpdates = NULL; | ||
| 51 | |||
| 52 | hr = GetAutomaticUpdatesService(&pAutomaticUpdates); | ||
| 53 | WuaExitOnFailure(hr, "Failed to get the Automatic Updates service."); | ||
| 54 | |||
| 55 | hr = pAutomaticUpdates->Resume(); | ||
| 56 | WuaExitOnFailure(hr, "Failed to resume the Automatic Updates service."); | ||
| 57 | |||
| 58 | LExit: | ||
| 59 | ReleaseObject(pAutomaticUpdates); | ||
| 60 | |||
| 61 | return hr; | ||
| 62 | } | ||
| 63 | |||
| 64 | extern "C" HRESULT DAPI WuaRestartRequired( | ||
| 65 | __out BOOL* pfRestartRequired | ||
| 66 | ) | ||
| 67 | { | ||
| 68 | HRESULT hr = S_OK; | ||
| 69 | ISystemInformation* pSystemInformation = NULL; | ||
| 70 | VARIANT_BOOL bRestartRequired; | ||
| 71 | |||
| 72 | hr = ::CoCreateInstance(__uuidof(SystemInformation), NULL, CLSCTX_INPROC_SERVER, __uuidof(ISystemInformation), reinterpret_cast<LPVOID*>(&pSystemInformation)); | ||
| 73 | WuaExitOnRootFailure(hr, "Failed to get WUA system information interface."); | ||
| 74 | |||
| 75 | hr = pSystemInformation->get_RebootRequired(&bRestartRequired); | ||
| 76 | WuaExitOnRootFailure(hr, "Failed to determine if restart is required from WUA."); | ||
| 77 | |||
| 78 | *pfRestartRequired = (VARIANT_FALSE != bRestartRequired); | ||
| 79 | |||
| 80 | LExit: | ||
| 81 | ReleaseObject(pSystemInformation); | ||
| 82 | |||
| 83 | return hr; | ||
| 84 | } | ||
| 85 | |||
| 86 | |||
| 87 | // internal function definitions | ||
| 88 | |||
| 89 | static HRESULT GetAutomaticUpdatesService( | ||
| 90 | __out IAutomaticUpdates **ppAutomaticUpdates | ||
| 91 | ) | ||
| 92 | { | ||
| 93 | HRESULT hr = S_OK; | ||
| 94 | CLSID clsidAutomaticUpdates = { }; | ||
| 95 | |||
| 96 | hr = ::CLSIDFromProgID(L"Microsoft.Update.AutoUpdate", &clsidAutomaticUpdates); | ||
| 97 | WuaExitOnFailure(hr, "Failed to get CLSID for Microsoft.Update.AutoUpdate."); | ||
| 98 | |||
| 99 | hr = ::CoCreateInstance(clsidAutomaticUpdates, NULL, CLSCTX_INPROC_SERVER, IID_IAutomaticUpdates, reinterpret_cast<LPVOID*>(ppAutomaticUpdates)); | ||
| 100 | WuaExitOnFailure(hr, "Failed to create instance of Microsoft.Update.AutoUpdate."); | ||
| 101 | |||
| 102 | LExit: | ||
| 103 | return hr; | ||
| 104 | } | ||
