Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

64bit windows registry - why is %ProgramFiles% converted to %ProgramFiles(x86)%?

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?

like image 769
Benjamin Avatar asked Jan 24 '26 06:01

Benjamin


1 Answers

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)

like image 148
Ana Betts Avatar answered Jan 25 '26 20:01

Ana Betts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!