Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. RegQueryValueEx returns wrong value

RegQueryValueEx returns wrong value

Scheduled Pinned Locked Moved C / C++ / MFC
databasesql-serversysadmintoolshelp
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vks11
    wrote on last edited by
    #1

    Hi all, While debugging the following code,

    inline LONG CRegKey::QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount)
    {
    ATLASSERT(pdwCount != NULL);
    DWORD dwType = NULL;
    LONG lRes = RegQueryValueEx(m_hKey, (LPTSTR)lpszValueName, NULL, &dwType,
    (LPBYTE)szValue, pdwCount);
    ATLASSERT((lRes!=ERROR_SUCCESS) || (dwType == REG_SZ) ||
    (dwType == REG_MULTI_SZ) || (dwType == REG_EXPAND_SZ));
    return lRes;
    }

    Here the value for (LPTSTR)lpszValueName is 'SQLPath' and the value which returns for 'szValue' in RegQueryValueEx method is “c:\Program Files (x86)\Microsoft SQL Server\100\Tools\” which should be “c:\Program Files\Microsoft SQL Server\100\Tools\” We have noted that the data value for SQLPath in RegistryKey "SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\ClientSetup" is “c:\Program Files\Microsoft SQL Server\100\Tools\” Could anybody please tell why RegQueryValueEx method is returning a wrong value “c:\Program Files (x86)\Microsoft SQL Server\100\Tools\” which should be “c:\Program Files\Microsoft SQL Server\100\Tools\” Thanks in advance

    L F 3 Replies Last reply
    0
    • V vks11

      Hi all, While debugging the following code,

      inline LONG CRegKey::QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount)
      {
      ATLASSERT(pdwCount != NULL);
      DWORD dwType = NULL;
      LONG lRes = RegQueryValueEx(m_hKey, (LPTSTR)lpszValueName, NULL, &dwType,
      (LPBYTE)szValue, pdwCount);
      ATLASSERT((lRes!=ERROR_SUCCESS) || (dwType == REG_SZ) ||
      (dwType == REG_MULTI_SZ) || (dwType == REG_EXPAND_SZ));
      return lRes;
      }

      Here the value for (LPTSTR)lpszValueName is 'SQLPath' and the value which returns for 'szValue' in RegQueryValueEx method is “c:\Program Files (x86)\Microsoft SQL Server\100\Tools\” which should be “c:\Program Files\Microsoft SQL Server\100\Tools\” We have noted that the data value for SQLPath in RegistryKey "SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\ClientSetup" is “c:\Program Files\Microsoft SQL Server\100\Tools\” Could anybody please tell why RegQueryValueEx method is returning a wrong value “c:\Program Files (x86)\Microsoft SQL Server\100\Tools\” which should be “c:\Program Files\Microsoft SQL Server\100\Tools\” Thanks in advance

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      It may be that you are running a 32 bit application, in which case it will use Program Files (x86), which is where the 32-bit versions are located.

      V 1 Reply Last reply
      0
      • V vks11

        Hi all, While debugging the following code,

        inline LONG CRegKey::QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount)
        {
        ATLASSERT(pdwCount != NULL);
        DWORD dwType = NULL;
        LONG lRes = RegQueryValueEx(m_hKey, (LPTSTR)lpszValueName, NULL, &dwType,
        (LPBYTE)szValue, pdwCount);
        ATLASSERT((lRes!=ERROR_SUCCESS) || (dwType == REG_SZ) ||
        (dwType == REG_MULTI_SZ) || (dwType == REG_EXPAND_SZ));
        return lRes;
        }

        Here the value for (LPTSTR)lpszValueName is 'SQLPath' and the value which returns for 'szValue' in RegQueryValueEx method is “c:\Program Files (x86)\Microsoft SQL Server\100\Tools\” which should be “c:\Program Files\Microsoft SQL Server\100\Tools\” We have noted that the data value for SQLPath in RegistryKey "SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\ClientSetup" is “c:\Program Files\Microsoft SQL Server\100\Tools\” Could anybody please tell why RegQueryValueEx method is returning a wrong value “c:\Program Files (x86)\Microsoft SQL Server\100\Tools\” which should be “c:\Program Files\Microsoft SQL Server\100\Tools\” Thanks in advance

        F Offline
        F Offline
        Freak30
        wrote on last edited by
        #3

        When a 32 bit application accesses the path starting with SOFTWARE under the key HKEY_LOCAL_MACHINE on a 64 bit OS, there is a Wow6432Node added automatically after the SOFTWARE. So the path you really accessed was "SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\100\Tools\ClientSetup" instead of the one you expected. Depening on what you want to use the information for, you may need to compile your app as x64.

        The good thing about pessimism is, that you are always either right or pleasently surprised.

        V 1 Reply Last reply
        0
        • V vks11

          Hi all, While debugging the following code,

          inline LONG CRegKey::QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount)
          {
          ATLASSERT(pdwCount != NULL);
          DWORD dwType = NULL;
          LONG lRes = RegQueryValueEx(m_hKey, (LPTSTR)lpszValueName, NULL, &dwType,
          (LPBYTE)szValue, pdwCount);
          ATLASSERT((lRes!=ERROR_SUCCESS) || (dwType == REG_SZ) ||
          (dwType == REG_MULTI_SZ) || (dwType == REG_EXPAND_SZ));
          return lRes;
          }

          Here the value for (LPTSTR)lpszValueName is 'SQLPath' and the value which returns for 'szValue' in RegQueryValueEx method is “c:\Program Files (x86)\Microsoft SQL Server\100\Tools\” which should be “c:\Program Files\Microsoft SQL Server\100\Tools\” We have noted that the data value for SQLPath in RegistryKey "SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\ClientSetup" is “c:\Program Files\Microsoft SQL Server\100\Tools\” Could anybody please tell why RegQueryValueEx method is returning a wrong value “c:\Program Files (x86)\Microsoft SQL Server\100\Tools\” which should be “c:\Program Files\Microsoft SQL Server\100\Tools\” Thanks in advance

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Hi, Add the KEY_WOW64_64KEY flag[^] to the samDesired parameter of RegOpenKeyExfunction [^]before passing the handle to RegQueryValueEx[^] if you want to avoid Registry Virtualization[^]. Best Wishes, -David Delaune

          V 1 Reply Last reply
          0
          • F Freak30

            When a 32 bit application accesses the path starting with SOFTWARE under the key HKEY_LOCAL_MACHINE on a 64 bit OS, there is a Wow6432Node added automatically after the SOFTWARE. So the path you really accessed was "SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\100\Tools\ClientSetup" instead of the one you expected. Depening on what you want to use the information for, you may need to compile your app as x64.

            The good thing about pessimism is, that you are always either right or pleasently surprised.

            V Offline
            V Offline
            vks11
            wrote on last edited by
            #5

            Thanks a lot!! :thumbsup:

            1 Reply Last reply
            0
            • L Lost User

              Hi, Add the KEY_WOW64_64KEY flag[^] to the samDesired parameter of RegOpenKeyExfunction [^]before passing the handle to RegQueryValueEx[^] if you want to avoid Registry Virtualization[^]. Best Wishes, -David Delaune

              V Offline
              V Offline
              vks11
              wrote on last edited by
              #6

              Thanks a lot David!! :thumbsup:

              1 Reply Last reply
              0
              • L Lost User

                It may be that you are running a 32 bit application, in which case it will use Program Files (x86), which is where the 32-bit versions are located.

                V Offline
                V Offline
                vks11
                wrote on last edited by
                #7

                Thanks a lot!!:thumbsup:

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups