diff --git a/UI/win-update/updater/updater.cpp b/UI/win-update/updater/updater.cpp index e9a8e1a251e1fa4444d36756e55562050b4cb2bd..0fa32636f5477c2f6ee4fecd959e252ef064ec52 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;