Search code examples
windows-7registrywin64

Where my Registry entry go ? windows 7, win64


Windows7 and Win64 is a new platform me, programming wise, so don't know what happened, I save a key in windows registry in windows7 64bit with the following command, the problem is that the same code is able to return REG_OPENED_EXISTING_KEY return value, which means the key creation was success and that the function is able to read/open the key in subsequent calls, but when I try to find the key in the location in regedit.exe, I can't it simply doesn't show in the tree neither in HKLM_LOCAL_MACHINE/Software/MyProject nor in HKLM_LOCAL_MACHINE/Software/Wow6432Node/MyProject

Can anybody please clear what's happening here ?

 HKEY hKey ;
 HKEY  key = HKEY_LOCAL_MACHINE;
 DWORD disValue ;
 string subKey = "Software\\MyProject\\";

 LONG retValue = RegCreateKeyEx( key, subKey.c_str(), 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, &disValue ) ;
 if ( retValue == ERROR_SUCCESS )
 {
    if ( disValue == REG_CREATED_NEW_KEY )// new key created. This value will change to REG_OPENED_EXISTING_KEY if the key already existed, the function then simply open the key.
       return true;
    return false;
 }

Solution

  • If your process is not running as Administrator, it will be unable to access HKLM\SOFTWARE. For compatibility reasons, Windows Vista and Windows 7 will then apply something called "registry virtualization". This redirects accesses to HKLM\SOFTWARE to somewhere that your process can access. It does something similar for legacy processes that attempt to write to C:\Program Files.

    How does Windows decide that your application is "legacy" and needs this compatibility hack? You need an application manifest to tell Windows that your process is Windows Vista-aware and that you don't want the hack.