提交 3c91fac1 编写于 作者: R Richard Stanway

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.
上级 f26941b5
......@@ -1153,17 +1153,31 @@ static bool Update(wchar_t *cmdLine)
GetCurrentDirectory(_countof(lpAppDataPath), lpAppDataPath);
StringCbCat(lpAppDataPath, sizeof(lpAppDataPath), L"\\config");
} else {
CoTaskMemPtr<wchar_t> 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<wchar_t> 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<wchar_t> 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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册