From 3f4622ffe01dfbaef87b0d715fef6c3cdec4c57d Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Mon, 14 Jan 2019 08:16:48 -0800 Subject: [PATCH] Fix StartupTests.StartsWithDotnetInstallLocation (#6589) --- .../CommonLib/HostFxrResolver.cpp | 17 +++++++++++++---- .../CommonLib/RegistryKey.cpp | 6 +++--- .../AspNetCoreModuleV2/CommonLib/RegistryKey.h | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp index 58ba32b43e..f553e2b3ea 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp @@ -259,13 +259,22 @@ HostFxrResolver::GetAbsolutePathToDotnet( } auto isWow64Process = Environment::IsRunning64BitProcess(); - const auto platform = isWow64Process? L"x64" : L"x86"; + + std::wstring regKeySubSection; + + if (isWow64Process) + { + regKeySubSection = L"SOFTWARE\\WOW6432Node\\dotnet\\Setup\\InstalledVersions\\x64\\sdk"; + } + else + { + regKeySubSection = L"SOFTWARE\\dotnet\\Setup\\InstalledVersions\\x86\\sdk"; + } const auto installationLocation = RegistryKey::TryGetString( HKEY_LOCAL_MACHINE, - std::wstring(L"SOFTWARE\\dotnet\\Setup\\InstalledVersions\\") + platform + L"\\sdk", - L"InstallLocation", - RRF_SUBKEY_WOW6432KEY); + regKeySubSection, + L"InstallLocation"); if (installationLocation.has_value()) { diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.cpp index 9f8bdeb409..63828821f9 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.cpp @@ -16,11 +16,11 @@ std::optional RegistryKey::TryGetDWORD(HKEY section, const std::wstring& return dwData; } -std::optional RegistryKey::TryGetString(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName, DWORD flags) +std::optional RegistryKey::TryGetString(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName) { DWORD cbData; - if (!CheckReturnValue(RegGetValue(section, subSectionName.c_str(), valueName.c_str(), RRF_RT_REG_SZ | flags, nullptr, nullptr, &cbData) != NO_ERROR)) + if (!CheckReturnValue(RegGetValue(section, subSectionName.c_str(), valueName.c_str(), RRF_RT_REG_SZ, nullptr, nullptr, &cbData))) { return std::nullopt; } @@ -28,7 +28,7 @@ std::optional RegistryKey::TryGetString(HKEY section, const std::w std::wstring data; data.resize(cbData / sizeof(wchar_t)); - if (!CheckReturnValue(RegGetValue(section, subSectionName.c_str(), valueName.c_str(), RRF_RT_REG_SZ | flags, nullptr, data.data(), &cbData) != NO_ERROR)) + if (!CheckReturnValue(RegGetValue(section, subSectionName.c_str(), valueName.c_str(), RRF_RT_REG_SZ, nullptr, data.data(), &cbData))) { return std::nullopt; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.h b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.h index 817e254f6f..d61466bcaa 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.h @@ -13,7 +13,7 @@ public: std::optional TryGetDWORD(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName, DWORD flags = 0); static - std::optional TryGetString(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName, DWORD flags = 0); + std::optional TryGetString(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName); private: static