Kaydet (Commit) 53058090 authored tarafından Mike Kaganski's avatar Mike Kaganski

tdf#121987: Don't fail installation if failed to enable WU service

Since commit 18828273, an attempt to
install UCRT will be performed regardless there is an evidence that it's
present on the system, to workaround some cases where the existing UCRT
is broken (tdf#115405, tdf#119910).

But that made other errors to emerge: on systems where users disable WU
service using some exotic ways, installer is unable to enable the
service, and fails. [1][2] Examples of such hard-disables are using
`sc delete` [3] and associating WU service with a guest account. Many
such cases are reported for Windows 10, where installation of the UCRT
is not required.

So the solution (imperfect, but possibly the best possible here) is to
allow installer to continue in case of failure enabling the service.
This will automatically eliminate all problems related to Win10; and
also for cases where users are advanced enough (the majority of such
hard-disable cases should be those), it might be enough to add a
relevant FAQ entry.

[1] https://ask.libreoffice.org/en/question/172227/cannot-install-631/
[2] https://ask.libreoffice.org/en/question/175571/installation-failed-unknown-error-win10x64/
[3] https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/sc-delete

Change-Id: Ie85016eb6f0667f39412a3089fe1b1855cb1fc73
Reviewed-on: https://gerrit.libreoffice.org/64825Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
Tested-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst adc10258
......@@ -166,6 +166,16 @@ bool IsWow64Process()
#endif
}
// An exception class to differentiate a non-fatal exception
class nonfatal_exception : public std::exception
{
public:
nonfatal_exception(const std::exception& e)
: std::exception(e)
{
}
};
// Checks if Windows Update service is disabled, and if it is, enables it temporarily.
class WUServiceEnabler
{
......@@ -195,27 +205,37 @@ public:
private:
static CloseServiceHandleGuard EnableWUService(MSIHANDLE hInstall)
{
auto hSCM = Guard(OpenSCManagerW(nullptr, nullptr, SC_MANAGER_ALL_ACCESS));
if (!hSCM)
ThrowLastError("OpenSCManagerW");
WriteLog(hInstall, "Opened service control manager");
auto hService = Guard(OpenServiceW(hSCM.get(), L"wuauserv",
SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG
| SERVICE_QUERY_STATUS | SERVICE_STOP));
if (!hService)
ThrowLastError("OpenServiceW");
WriteLog(hInstall, "Obtained WU service handle");
if (ServiceStatus(hInstall, hService.get()) == SERVICE_RUNNING
|| !EnsureServiceEnabled(hInstall, hService.get(), true))
try
{
// No need to restore anything back, since we didn't change config
hService.reset();
WriteLog(hInstall, "Service configuration is unchanged");
}
auto hSCM = Guard(OpenSCManagerW(nullptr, nullptr, SC_MANAGER_ALL_ACCESS));
if (!hSCM)
ThrowLastError("OpenSCManagerW");
WriteLog(hInstall, "Opened service control manager");
auto hService = Guard(OpenServiceW(hSCM.get(), L"wuauserv",
SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG
| SERVICE_QUERY_STATUS | SERVICE_STOP));
if (!hService)
ThrowLastError("OpenServiceW");
WriteLog(hInstall, "Obtained WU service handle");
if (ServiceStatus(hInstall, hService.get()) == SERVICE_RUNNING
|| !EnsureServiceEnabled(hInstall, hService.get(), true))
{
// No need to restore anything back, since we didn't change config
hService.reset();
WriteLog(hInstall, "Service configuration is unchanged");
}
return hService;
return hService;
}
catch (const std::exception& e)
{
// Allow errors opening service to be logged, but not interrupt installation.
// They are likely to happen in situations where people hard-disable WU service,
// and for these cases, let people deal with install logs instead of failing.
throw nonfatal_exception(e);
}
}
// Returns if the service configuration was actually changed
......@@ -476,6 +496,14 @@ extern "C" __declspec(dllexport) UINT __stdcall InstallMSU(MSIHANDLE hInstall)
ThrowWin32Error("Execution of wusa.exe", nExitCode);
}
}
catch (nonfatal_exception& e)
{
// An error that should not interrupt installation
WriteLog(hInstall, e.what());
WriteLog(hInstall, "Installation of MSU package failed, but installation of product will "
"continue. You may need to install the required update manually");
return ERROR_SUCCESS;
}
catch (std::exception& e)
{
WriteLog(hInstall, e.what());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment