CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Registry access in Windows 7

  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,625

    Registry access in Windows 7

    I'm working on a program which uses RegOpenKey() and RegQueryValueEx() to access a particular registry key. Usually the key gets accessed like this:-

    Code:
    HKEY_CURRENT_USER\Software\Jack
    but I've just noticed that if I change it to this, it fails on Windows 7:-

    Code:
    HKEY_CURRENT_USER\SOFTWARE\Jack
    Although it seems to still work in Win8.1 - so is registry access case-sensitive in Win7? I'm just curious because that'd be quite unusual for Windows.
    "A problem well stated is a problem half solved. - Charles F. Kettering

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,400

    Re: Registry access in Windows 7

    I believe the registry has always been case sensitive.

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,625

    Re: Registry access in Windows 7

    Thanks Arjay - after a bit more experimenting I've realised there's an extra element to this... it only seems to happen if I run a 32-bit app on Win64. Initially, the app tries to open its regkey like this:-

    Code:
    RegOpenKeyExA (HKEY_CURRENT_USER, "Software\\Jack", 0, KEY_READ, &key);
    For a 32-bit app on Win32, that call seems to succeed - regardless of upper case / mixed case etc. But for a 32-bit app on a Win64, that call only succeeds if the case is correct. And even then, it only succeeds for HKEY_CURRENT_USER. If we try to open a key under HKEY_LOCAL_MACHINE, we need to change the above call to this:-

    Code:
    RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\Jack", 0, KEY_READ, &key);
    But regardless of case, the above call always fails (even if the key exists) and the program then tries again, like this:-

    Code:
    RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\Jack", 0, KEY_READ | KEY_WOW64_32KEY, &key);
    But the 'KEY_WOW64_32KEY' option seems to always fail too (again, regardless of upper case / mixed case etc). So I'm guessing the 2nd option isn't quite right if a 32-bit app needs to open a HKEY_LOCAL_MACHINE key on Win64

    Or does HKEY_LOCAL_MACHINE have stricter access permissions maybe??
    Last edited by John E; November 3rd, 2020 at 05:59 AM.
    "A problem well stated is a problem half solved. - Charles F. Kettering

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,400

    Re: Registry access in Windows 7

    There is some msdn documentation on how the registry stores values fir 32bit apps running on 64bit windows. Sorry I don't have a direct link.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,848

    Re: Registry access in Windows 7

    Quote Originally Posted by John E View Post
    I'm working on a program which uses RegOpenKey() and RegQueryValueEx().....

    ... so is registry access case-sensitive in Win7? I'm just curious because that'd be quite unusual for Windows.
    According to docs:
    Parameters
    hKey

    A handle to an open registry key. This handle is returned by the RegCreateKeyEx or RegOpenKeyEx function, or it can be one of the following predefined keys:

    HKEY_CLASSES_ROOT HKEY_CURRENT_CONFIG HKEY_CURRENT_USER HKEY_LOCAL_MACHINE HKEY_USERS

    lpSubKey

    The name of the registry subkey to be opened.

    Key names are not case sensitive.
    So both:
    Code:
    RegOpenKeyExA (HKEY_CURRENT_USER, "Software\\Jack",
    and
    Code:
    RegOpenKeyExA (HKEY_CURRENT_USER, "SOFTWARE\\Jack",
    should you give the same result.

    BTW, what error do you get?
    Victor Nijegorodov

  6. #6
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,625

    Re: Registry access in Windows 7

    RegOpenKeyExA() is returning a value of 2 (ERROR_FILE_NOT_FOUND)

    Quote Originally Posted by John E View Post
    it only seems to happen if I run a 32-bit app on Win64
    This probably won't sound right but here's what seems to be happening...

    On 64-bit Windows, if a 32-bit app tries to query HKEY_LOCAL_MACHINE\SOFTWARE, Windows seems to assume that the required key will be found under WOW6432Node. AFAICT the other nodes in SOFTWARE simply don't get searched - they only get searched if the requesting app is 64-bit. What's strange is that HKEY_CURRENT_USER\Software also has a node called WOW6432Node - but that one only gets used for Microsoft software, so the same assumption doesn't seem to apply there - i.e. everything under HKEY_CURRENT_USER\Software will get searched.
    Last edited by John E; November 4th, 2020 at 10:06 AM.
    "A problem well stated is a problem half solved. - Charles F. Kettering

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,400

    Re: Registry access in Windows 7

    Quote Originally Posted by John E View Post
    RegOpenKeyExA() is returning a value of 2 (ERROR_FILE_NOT_FOUND)



    This probably won't sound right but here's what seems to be happening...

    On 64-bit Windows, if a 32-bit app tries to query HKEY_LOCAL_MACHINE\SOFTWARE, Windows seems to assume that the required key will be found under WOW6432Node. AFAICT the other nodes in SOFTWARE simply don't get searched - they only get searched if the requesting app is 64-bit. What's strange is that HKEY_CURRENT_USER\Software also has a node called WOW6432Node - but that one only gets used for Microsoft software, so the same assumption doesn't seem to apply there - i.e. everything under HKEY_CURRENT_USER\Software will get searched.
    See post #4

  8. #8
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,625

    Re: Registry access in Windows 7

    Quote Originally Posted by Arjay View Post
    See post #4
    Thanks Arjay - I came across this item which mentions an extra parameter called KEY_WOW64_64KEY. It can be used by a 32-bit app to force Windows to examine 64-bit keys when running on a 64-bit OS. AFAICT there's no detriment when the app gets run in Win32.
    "A problem well stated is a problem half solved. - Charles F. Kettering

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)