0

We are trying to determine if auto rotation is currently enabled or disabled from our c++ application. The following code always returns a value of 1 even if regedit of the same key shows 0. It returns the same if the application is run as a standard user or as an administrator.

HKEY hkMain;
LONG lRes =  RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AutoRotation",0,KEY_QUERY_VALUE,&hkMain);
if (lRes==ERROR_SUCCESS) {
    DWORD dwRegValue=0,dwSize=0,dwType=0;
    dwSize = sizeof(DWORD);
    lRes = RegQueryValueEx(hkMain,TEXT("Enable"),NULL,&dwType,(LPBYTE)&dwRegValue,&dwSize);

    if (lRes==ERROR_SUCCESS) {
        // dwRegValue value is always 1
    }
    RegCloseKey(hkMain);
}
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
PhilC
  • 291
  • 1
  • 14
  • Maybe I'm not following you, but it looks like you are checking the value of lRes as if it's the data from the "Enable" registry value? lRes is just the status code for the operation (eg, did trying to read the value succeed?). Your data should be in dwRegValue. – Matthew Feb 07 '13 at 20:25
  • no, we are only checking lRes for success on registry function calls dwRegValue is always 1. I editted the post to make this clearer – PhilC Feb 07 '13 at 20:29
  • Ah, your extra comment there cleared that up for me. – Matthew Feb 07 '13 at 20:31
  • You are probably looking at the wrong key with Regedit. Navigate to SOFTWARE\Wow6432Node\Microsoft\... instead on a 64-bit operating system. That's the home for keys read by 32-bit programs. – Hans Passant Feb 07 '13 at 23:10
  • That is exactly what is happening, thank you very much. My next question would be how to access the *real* value from our 32 bit application? – PhilC Feb 08 '13 at 12:59
  • now that I know what to look for it was easy to find the answer. Need to include KEY_WOW64_64KEY flag in our registry function calls. Thank you for your help. It does not look like there is a way to mark a comment as the answer. what is the appropriate way to mark this as answered? – PhilC Feb 08 '13 at 13:16
  • I think the only thing there is to do is answer your own question. It's allowed. – Matthew Feb 08 '13 at 16:26

1 Answers1

0

Hans Passant's comment provided the answer "You are probably looking at the wrong key with Regedit. Navigate to SOFTWARE\Wow6432Node\Microsoft... instead on a 64-bit operating system. That's the home for keys read by 32-bit programs. " We Needed to include KEY_WOW64_64KEY flag in our registry function calls. Thank you

PhilC
  • 291
  • 1
  • 14