From 5d8375007754101ff2889d0e79486c8f9b7cf5ab Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 3 Sep 2017 11:22:38 -0700 Subject: Initial commit --- src/dutil/wuautil.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/dutil/wuautil.cpp (limited to 'src/dutil/wuautil.cpp') 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 @@ +// 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(&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(ppAutomaticUpdates)); + ExitOnFailure(hr, "Failed to create instance of Microsoft.Update.AutoUpdate."); + +LExit: + return hr; +} -- cgit v1.2.3-55-g6feb