diff options
Diffstat (limited to 'src/dutil/wuautil.cpp')
| -rw-r--r-- | src/dutil/wuautil.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/dutil/wuautil.cpp b/src/dutil/wuautil.cpp new file mode 100644 index 00000000..94ab659d --- /dev/null +++ b/src/dutil/wuautil.cpp | |||
| @@ -0,0 +1,89 @@ | |||
| 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 | // internal function declarations | ||
| 7 | |||
| 8 | static HRESULT GetAutomaticUpdatesService( | ||
| 9 | __out IAutomaticUpdates **ppAutomaticUpdates | ||
| 10 | ); | ||
| 11 | |||
| 12 | |||
| 13 | // function definitions | ||
| 14 | |||
| 15 | extern "C" HRESULT DAPI WuaPauseAutomaticUpdates() | ||
| 16 | { | ||
| 17 | HRESULT hr = S_OK; | ||
| 18 | IAutomaticUpdates *pAutomaticUpdates = NULL; | ||
| 19 | |||
| 20 | hr = GetAutomaticUpdatesService(&pAutomaticUpdates); | ||
| 21 | ExitOnFailure(hr, "Failed to get the Automatic Updates service."); | ||
| 22 | |||
| 23 | hr = pAutomaticUpdates->Pause(); | ||
| 24 | ExitOnFailure(hr, "Failed to pause the Automatic Updates service."); | ||
| 25 | |||
| 26 | LExit: | ||
| 27 | ReleaseObject(pAutomaticUpdates); | ||
| 28 | |||
| 29 | return hr; | ||
| 30 | } | ||
| 31 | |||
| 32 | extern "C" HRESULT DAPI WuaResumeAutomaticUpdates() | ||
| 33 | { | ||
| 34 | HRESULT hr = S_OK; | ||
| 35 | IAutomaticUpdates *pAutomaticUpdates = NULL; | ||
| 36 | |||
| 37 | hr = GetAutomaticUpdatesService(&pAutomaticUpdates); | ||
| 38 | ExitOnFailure(hr, "Failed to get the Automatic Updates service."); | ||
| 39 | |||
| 40 | hr = pAutomaticUpdates->Resume(); | ||
| 41 | ExitOnFailure(hr, "Failed to resume the Automatic Updates service."); | ||
| 42 | |||
| 43 | LExit: | ||
| 44 | ReleaseObject(pAutomaticUpdates); | ||
| 45 | |||
| 46 | return hr; | ||
| 47 | } | ||
| 48 | |||
| 49 | extern "C" HRESULT DAPI WuaRestartRequired( | ||
| 50 | __out BOOL* pfRestartRequired | ||
| 51 | ) | ||
| 52 | { | ||
| 53 | HRESULT hr = S_OK; | ||
| 54 | ISystemInformation* pSystemInformation = NULL; | ||
| 55 | VARIANT_BOOL bRestartRequired; | ||
| 56 | |||
| 57 | hr = ::CoCreateInstance(__uuidof(SystemInformation), NULL, CLSCTX_INPROC_SERVER, __uuidof(ISystemInformation), reinterpret_cast<LPVOID*>(&pSystemInformation)); | ||
| 58 | ExitOnRootFailure(hr, "Failed to get WUA system information interface."); | ||
| 59 | |||
| 60 | hr = pSystemInformation->get_RebootRequired(&bRestartRequired); | ||
| 61 | ExitOnRootFailure(hr, "Failed to determine if restart is required from WUA."); | ||
| 62 | |||
| 63 | *pfRestartRequired = (VARIANT_FALSE != bRestartRequired); | ||
| 64 | |||
| 65 | LExit: | ||
| 66 | ReleaseObject(pSystemInformation); | ||
| 67 | |||
| 68 | return hr; | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | // internal function definitions | ||
| 73 | |||
| 74 | static HRESULT GetAutomaticUpdatesService( | ||
| 75 | __out IAutomaticUpdates **ppAutomaticUpdates | ||
| 76 | ) | ||
| 77 | { | ||
| 78 | HRESULT hr = S_OK; | ||
| 79 | CLSID clsidAutomaticUpdates = { }; | ||
| 80 | |||
| 81 | hr = ::CLSIDFromProgID(L"Microsoft.Update.AutoUpdate", &clsidAutomaticUpdates); | ||
| 82 | ExitOnFailure(hr, "Failed to get CLSID for Microsoft.Update.AutoUpdate."); | ||
| 83 | |||
| 84 | hr = ::CoCreateInstance(clsidAutomaticUpdates, NULL, CLSCTX_INPROC_SERVER, IID_IAutomaticUpdates, reinterpret_cast<LPVOID*>(ppAutomaticUpdates)); | ||
| 85 | ExitOnFailure(hr, "Failed to create instance of Microsoft.Update.AutoUpdate."); | ||
| 86 | |||
| 87 | LExit: | ||
| 88 | return hr; | ||
| 89 | } | ||
