简体   繁体   中英

Windows 8 AutoRotation registry value

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'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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM