Strange behavior with RegOpenKeyEx


In work I encounter a strange behavior of our product, which found can be boiled down to the weird behavior of Windows API RegOpenKeyEx. Below is my test code:

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

int main(int argc, char* argv[])
    HKEY hk;
    LONG lreturn = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
    TEXT("Software\\Mercury Interactive\\LoadRunner\\Vugen\\Logger\\media"),
    &hk ); 

    char a ;
    scanf("%c ", &a);

    return 0;

On my local machine, the above program prompts "YES," while running on another remote virtual machine it outputs "NO."

On Both machine, registry key "Software\Mercury Interactive\LoadRunner\Vugen\Logger\media" exists under HKEY_CURRENT_USER rather than HKEY_LOCAL_MACHINE.

So I am baffled why it ouputs "YES" on local machine? And stranger still, why it behaviors differently on the two machines? Local machine is Win7 64bit. Remote virtual machine is Win7 32bit. The program is compiled as 32bit.

This sounds a bit like Registry Virtualization, if the local machine has a entry in the VirtualStore (A previous Create call during development?) the open call will succeed even if the key does not exist under HKLM.

To get to the bottom of this you could run Process Monitor...