0

Following the following MSDN guide I'm trying to read a sample registry entry myself. I was adding my own registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion

My registry looks like this:

enter image description here

As you can see, I added a new value Test which I'm trying to read with the following C code:

#include <stdio.h>
#include <Windows.h>

int rd() {
    DWORD dataSize = {0};
    LONG result = RegGetValue(
        HKEY_LOCAL_MACHINE,
        L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 
        L"Test",        // Value
        RRF_RT_REG_SZ,  // Flags, REG_SZ
        0,              // Type, non specified
        0,              // Data, empty for now
        &dataSize);     // Getting the size only 

    printf(":length of that registry: %d\n", dataSize);
    return result;
}

int main(void) {
    int ans = rd();
    printf("exit code: %d \n", ans);    
    return 0;
}

The error code is 2 which means ERROR_FILE_NOT_FOUND. However if I'm trying ti change the value from test to CommonFilesDir for example: the error code is 0 which means success.

After writing down the registry I restarted my machine.

How is it that I can find some registry values and some not where both seem to exist in the Windows Registry Editor?

shaqed
  • 342
  • 3
  • 17
  • "After writing down the registry I restarted my machine." ? – Stargateur Apr 15 '18 at 20:26
  • Read somewhere that changes in the registry requires system reboot... Your question makes me think this may be not true – shaqed Apr 15 '18 at 20:32
  • Is it the registry redirector that is confusing you? – David Heffernan Apr 15 '18 at 20:40
  • I'm clearly not a expect in windows, but I suppose some key are used by windows and need a restart to work, but some key are just use by process and maybe just require to restart this process. I just wondering why you tell us you restart your OS, and your answer is perfectly valid for me, as a non windows developer. – Stargateur Apr 15 '18 at 20:41
  • @star nope, no restart needed – David Heffernan Apr 15 '18 at 20:42

1 Answers1

0

I think this is a case of registry virtualization which is applied to HKEY_LOCAL_MACHINE\Software. That is you've edited non-virtualized branch with 64 bit editor and then tried to read virtualized branch with 32-bit program.

user7860670
  • 35,849
  • 4
  • 58
  • 84