8

Could anybody tell me what's wrong is with this code? There is no errors. Everything returns ERROR_SUCCESS but in register can't see any changes.

void Utils::writePath(LPCTSTR data)
{
    HKEY hkey;
    DWORD dwDisposition;
    if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, 
      TEXT("SOFTWARE\\aaTestCompany\\testApp"), 
      0, NULL, 0, 
      KEY_WRITE, NULL, 
      &hkey, &dwDisposition) == ERROR_SUCCESS) 
    {
        long setRes = RegSetValueEx (hkey, "testPath", 0, REG_SZ, (LPBYTE)data, strlen(data)+1);
         if (setRes == ERROR_SUCCESS) {
                printf("Success writing to Registry.");
            } else {
                printf("Error writing to Registry.");
            }
        RegCloseKey(hkey);
    }
    else
        MessageBox(NULL,"error","",0);
}
Charlie Hopperson
  • 415
  • 1
  • 9
  • 23

2 Answers2

23

As the application is 32-bit on a 64-bit OS the registry key will actually be created beneath HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node.

See 32-bit and 64-bit Application Data in the Registry.

hmjd
  • 120,187
  • 20
  • 207
  • 252
  • 2
    Amazing how many people don't read/know this. It's asked several times a week in many places online. – Deanna Jan 29 '13 at 15:05
  • 2
    @Deanna: Not everybody is expert in everything ;) – andreas Mar 02 '15 at 14:05
  • What should be done to set the key under the actual specified path? – user1198065 Jul 16 '15 at 21:25
  • @user1198065 Just read the documentation. The page pointed to by the link [hmjd](http://stackoverflow.com/users/1033896) posted references [Accessing an Alternate Registry View](https://msdn.microsoft.com/en-us/library/windows/desktop/aa384129.aspx) which offers exactly the information you are looking for. The same information can already be found on [Registry Key Security and Access Rights](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724878.aspx). Hint: `KEY_WOW64_64KEY`/`KEY_WOW64_32KEY` – Max Truxa Aug 20 '15 at 11:36
  • In my case the CLSID's were being registered at HKLM\Wow6432Node (no SOFTWARE path). – aaronsnoswell Sep 24 '15 at 04:14
0

Can you try with 5th and 6th parameters as REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS

surega
  • 707
  • 7
  • 15