April 02, 2009

Read/Write Windows Registry on Windows 64-Bits Platforms

On Windows Vista 64-bits, there's a 32-bits emulator called WOW64 for 32-bits applications. A 32-bits application running on WOW64 uses the registry redirector, because the 64-bit version of an application may use different registry keys and values than the 32-bit version.

For 32-bits application:
On 64-bit platforms, it runs on WOW64 and accesses 32-bit registry (inside Wow6432Node).

For 64-bits application:
On 64-bit platforms, it runs natively and accesses 64-bit registry (not inside Wow6432Node).

Whatever, you can explicitly indicate which version of registry you want to access, just use RegOpenKeyEx function with KEY_WOW64_32KEY or KEY_WOW64_64KEY in the desired access rights parameter.

Example: A 32-bit application running on WOW64 accesses the 64-bit registry

HKEY hkResult = NULL;
REGSAM samDesired = KEY_READ | KEY_WOW64_64KEY;
LONG lRetOpen = ::RegOpenKeyExW(
  L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Media Center",
  NULL, samDesired, &hkResult);

Reference on MSDN:
32-bit and 64-bit Application Data in the Registry