summaryrefslogtreecommitdiff
path: root/external/onlineupdate/install_updateservice.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-12-17 16:56:15 +0100
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-12-18 09:46:07 +0100
commit5b2674b278fd48700409079803fbaf7ea177be61 (patch)
tree46072c50bfc373aba0eaff8ca062a8bed695b8fc /external/onlineupdate/install_updateservice.cxx
parent85b33eaab7462e72dfb426d8f268e061dcaf89ba (diff)
tdf#164225: Only install MAR update_service when it will be needed
...where "will be needed" is approximated by "install location is under C:\Program Files" (i.e., where admin privileges will be necessary to do an update) Change-Id: I00c93df8c0c2c5132fffa4056b88af098cb4a644 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178679 Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de> Tested-by: Jenkins
Diffstat (limited to 'external/onlineupdate/install_updateservice.cxx')
-rw-r--r--external/onlineupdate/install_updateservice.cxx18
1 files changed, 18 insertions, 0 deletions
diff --git a/external/onlineupdate/install_updateservice.cxx b/external/onlineupdate/install_updateservice.cxx
index c1d547156098..47c90bc148d6 100644
--- a/external/onlineupdate/install_updateservice.cxx
+++ b/external/onlineupdate/install_updateservice.cxx
@@ -18,6 +18,7 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <msiquery.h>
+#include <shlobj.h>
#include <pathhash.h>
@@ -80,6 +81,23 @@ CloseHandleGuard guard(HANDLE handle) { return CloseHandleGuard(handle, CloseHan
bool runExecutable(std::wstring const& installLocation, wchar_t const* argument)
{
+ bool use = false;
+ PWSTR progPath;
+ if (SHGetKnownFolderPath(FOLDERID_ProgramFiles, 0, nullptr, &progPath) == S_OK)
+ {
+ auto const n = wcslen(progPath);
+ // For SHGetKnownFolderPath it is guaranteed that "The returned path does not include a
+ // trailing backslash":
+ use = (installLocation.size() == n
+ || (installLocation.size() > n && installLocation[n] == L'\\'))
+ && _wcsnicmp(progPath, installLocation.data(), n) == 0;
+ }
+ CoTaskMemFree(progPath);
+ if (!use)
+ {
+ return true;
+ }
+
std::wstring cmdline(L"\"");
cmdline += installLocation;
cmdline += L"\\program\\update_service.exe\" ";