Question

After running following codes, in 32bit process, the data %ProgramFiles% converted automatically.

HKEY hSubKey;
DWORD dwState;
RegCreateKeyEx(HKEY_CURRENT_USER, L"TestKey", NULL, NULL,
   REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hSubKey, &dwState);
std::wstring data = L"%ProgramFiles%";
RegSetValueEx(hSubKey, L"TestValue", NULL, REG_EXPAND_SZ,
  (BYTE*)data.c_str(), (DWORD)(data.size() * sizeof(WCHAR)) + sizeof(WCHAR));

The Result
enter image description here <- What the hell. Who expands it?

I don't want to convert the data. -But I have to use type REG_EXPAND_SZ.
How do I do?

Was it helpful?

Solution

This is called Registry value redirection, and it's a part of WOW64's Registry Virtualization. You can't disable this on Server 2003 or Vista, but you can in Win7 (can't remember the flag off the top of my head though). Why do you want to write keys pointing to the 64-bit Program Files from a 32-bit application? (there are legit answers to this question, I'm trying to figure out the scenario more)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top