From 66160d6973b41040f6b2066a84359147258f60c3 Mon Sep 17 00:00:00 2001 From: Christian Heimlich Date: Tue, 31 Oct 2023 21:30:10 -0400 Subject: [PATCH] win: improve accuracy of ProductName between arch (#4191) uv_os_uname() on Windows queries the registry value "HKEY_LOCAL_MACHINE\ SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName" to fill uv_utsname_t. If calling application was compiled for x86 and run on a x86_64 host, that query is redirected to "Computer\HKEY_LOCAL_MACHINE\ SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\ProductName" instead. For whatever reason, the value of 'ProductName' in the 32-bit registry section on 64-bit Windows sometimes differs from the 64-bit equivalent value and is inaccurate (e.g. containing the data "Windows 10 Enterprise" while the 64-bit value accurately contains "Windows 10 Pro"). Adds the 'KEY_WOW64_64KEY' security descriptor when opening the appropriate registry key so that the value of ProductName is always taken from the primary registry on 64-bit systems, regardless of compiled architecture. The descriptor is safely ignored on 32-bit hosts. --- src/win/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win/util.c b/src/win/util.c index 58b8e106..91d88a54 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -1506,7 +1506,7 @@ int uv_os_uname(uv_utsname_t* buffer) { r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, - KEY_QUERY_VALUE, + KEY_QUERY_VALUE | KEY_WOW64_64KEY, ®istry_key); if (r == ERROR_SUCCESS) {