From 3c91fac18ed36f82df33c3e91943e0e3b0bbb9cb Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Sun, 14 Jun 2020 01:35:48 +0200 Subject: [PATCH] UI/updater: Fix running updater as different user If the elevated user was a different user account, the updater would look in the wrong user's appdata for the manifest and fail. --- UI/win-update/updater/updater.cpp | 34 +++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/UI/win-update/updater/updater.cpp b/UI/win-update/updater/updater.cpp index e9a8e1a25..0fa32636f 100644 --- a/UI/win-update/updater/updater.cpp +++ b/UI/win-update/updater/updater.cpp @@ -1153,17 +1153,31 @@ static bool Update(wchar_t *cmdLine) GetCurrentDirectory(_countof(lpAppDataPath), lpAppDataPath); StringCbCat(lpAppDataPath, sizeof(lpAppDataPath), L"\\config"); } else { - CoTaskMemPtr pOut; - HRESULT hr = SHGetKnownFolderPath(FOLDERID_RoamingAppData, - KF_FLAG_DEFAULT, nullptr, - &pOut); - if (hr != S_OK) { + DWORD ret; + ret = GetEnvironmentVariable(L"OBS_USER_APPDATA_PATH", + lpAppDataPath, + _countof(lpAppDataPath)); + + if (ret >= _countof(lpAppDataPath)) { Status(L"Update failed: Could not determine AppData " L"location"); return false; } - StringCbCopy(lpAppDataPath, sizeof(lpAppDataPath), pOut); + if (!ret) { + CoTaskMemPtr pOut; + HRESULT hr = SHGetKnownFolderPath( + FOLDERID_RoamingAppData, KF_FLAG_DEFAULT, + nullptr, &pOut); + if (hr != S_OK) { + Status(L"Update failed: Could not determine AppData " + L"location"); + return false; + } + + StringCbCopy(lpAppDataPath, sizeof(lpAppDataPath), + pOut); + } } StringCbCat(lpAppDataPath, sizeof(lpAppDataPath), L"\\obs-studio"); @@ -1585,6 +1599,14 @@ static int RestartAsAdmin(LPCWSTR lpCmdLine, LPCWSTR cwd) * windows :( */ AllowSetForegroundWindow(ASFW_ANY); + /* if the admin is a different user, save the path to the user's + * appdata so we can load the correct manifest */ + CoTaskMemPtr pOut; + HRESULT hr = SHGetKnownFolderPath(FOLDERID_RoamingAppData, + KF_FLAG_DEFAULT, nullptr, &pOut); + if (hr == S_OK) + SetEnvironmentVariable(L"OBS_USER_APPDATA_PATH", pOut); + if (ShellExecuteEx(&shExInfo)) { DWORD exitCode; -- GitLab