I have trouble understanding the VirtualStore virtualization of registry operations in Vista and/or Windows 7. I thought trying to write something into the HKEY_LOCAL_MACHINE root while running as a standard user would prompt Windows to virtualize the operation and write to HKEY_CURRENT_USER/Classes/VirtualStore/MACHINE instead. I've seen several older applications behave exactly like that.
However, when trying to replicate that behaviour in C# and .Net4, the write operation to HKLM just fails with an UnauthorizedAccessException instead. Is there some way to force virtualization?
To give some context to the question: I'm trying to read and manipulate registry keys originally created by another legacy app. In Vista or Windows 7 these will be located in the VirtualStore. I'd like to use the same registry access logic both for WinXP and above and thought my registry operations would be virtualized just the same as the operations from the legacy app (and would operate on the same keys, because of that). This doesn't work as expected and the only workaround I know is to specifically access the VirtualStore path, if the user is running Vista or 7 and has UAC enabled... seems ugly, though, especially if Microsoft decides to change virtualization behaviour in future Windows versions.