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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Get Value From Registry Key

Get Value From Registry Key

Scheduled Pinned Locked Moved C / C++ / MFC
windows-admin
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.
  • M Offline
    M Offline
    Matthew Devine
    wrote on last edited by
    #1

    Alright lets say I want to get the value from a particular registry key. How would I go about programming that to actually accomplish this feat. Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Test Name: home value: testvalue

    B T 2 Replies Last reply
    0
    • M Matthew Devine

      Alright lets say I want to get the value from a particular registry key. How would I go about programming that to actually accomplish this feat. Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Test Name: home value: testvalue

      B Offline
      B Offline
      Blake Miller
      wrote on last edited by
      #2

      RegOpenKeyEx followed by RegQueryValueEx followed by RegCloseKey

      M 1 Reply Last reply
      0
      • B Blake Miller

        RegOpenKeyEx followed by RegQueryValueEx followed by RegCloseKey

        M Offline
        M Offline
        Matthew Devine
        wrote on last edited by
        #3

        Would this correctly output the value located in said key, with the name of "home" into the variable value that I've defined. char* value = NULL; LONG l = 0L; HKEY hKey = {0}; l = RegOpenKeyEx ( HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\Test"), 0, KEY_NOTIFY, &hKey ); if(l == ERROR_SUCCESS) { // The following call will wait until a change is made to the registry key. l = RegQueryValueEx( hKey, TEXT("home"), NULL, NULL, value); RegCloseKey(hKey);

        1 Reply Last reply
        0
        • M Matthew Devine

          Alright lets say I want to get the value from a particular registry key. How would I go about programming that to actually accomplish this feat. Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Test Name: home value: testvalue

          T Offline
          T Offline
          ThatsAlok
          wrote on last edited by
          #4

          Matthew Devine wrote: I want to get the value from a particular registry key Use CRegKey defined in atlbase.h Matthew Devine wrote: actually accomplish this feat. Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Test Name: home value: testvalue here is the small piece of code to accomplish that :)

          CRegKey l_regKey;

          // Open registry location
          if( l_regKey.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\Test")!=ERROR_SUCCESS))
          return;

          // now as you mentioned you want to retrieve String value
          DWORD dwCount=0;

          // Make a False call to retrieve the data length
          l_regKey.QueryValue(NULL,_T("home"),&dwCount);

          // now allocate string size
          LPTSTR pszRetStr=new TCHAR[dwCount+1];

          // Now retrieve the value from registry
          if(l_regKey.QueryValue(pszRetStr,_T("home"),&dwCount)==ERROR_SUCCESS)
          {
          MessageBox(pszRetStr,_T("Registry Value"));
          }

          // delete memory allocated to pszRetStr;
          

          if(pszRetStr)
          {
          delete [] pszRetStr;
          pszRetStr=NULL;
          }

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          cheers, Alok Gupta

          M 2 Replies Last reply
          0
          • T ThatsAlok

            Matthew Devine wrote: I want to get the value from a particular registry key Use CRegKey defined in atlbase.h Matthew Devine wrote: actually accomplish this feat. Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Test Name: home value: testvalue here is the small piece of code to accomplish that :)

            CRegKey l_regKey;

            // Open registry location
            if( l_regKey.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\Test")!=ERROR_SUCCESS))
            return;

            // now as you mentioned you want to retrieve String value
            DWORD dwCount=0;

            // Make a False call to retrieve the data length
            l_regKey.QueryValue(NULL,_T("home"),&dwCount);

            // now allocate string size
            LPTSTR pszRetStr=new TCHAR[dwCount+1];

            // Now retrieve the value from registry
            if(l_regKey.QueryValue(pszRetStr,_T("home"),&dwCount)==ERROR_SUCCESS)
            {
            MessageBox(pszRetStr,_T("Registry Value"));
            }

            // delete memory allocated to pszRetStr;
            

            if(pszRetStr)
            {
            delete [] pszRetStr;
            pszRetStr=NULL;
            }

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta

            M Offline
            M Offline
            Matthew Devine
            wrote on last edited by
            #5

            Thanks alot for the help, I was able to implement your code perfectly Alok. Again much appreciated.

            T 1 Reply Last reply
            0
            • M Matthew Devine

              Thanks alot for the help, I was able to implement your code perfectly Alok. Again much appreciated.

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              Matthew Devine wrote: Thanks alot for the help, Mention Not Please :)

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta

              1 Reply Last reply
              0
              • T ThatsAlok

                Matthew Devine wrote: I want to get the value from a particular registry key Use CRegKey defined in atlbase.h Matthew Devine wrote: actually accomplish this feat. Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Test Name: home value: testvalue here is the small piece of code to accomplish that :)

                CRegKey l_regKey;

                // Open registry location
                if( l_regKey.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\Test")!=ERROR_SUCCESS))
                return;

                // now as you mentioned you want to retrieve String value
                DWORD dwCount=0;

                // Make a False call to retrieve the data length
                l_regKey.QueryValue(NULL,_T("home"),&dwCount);

                // now allocate string size
                LPTSTR pszRetStr=new TCHAR[dwCount+1];

                // Now retrieve the value from registry
                if(l_regKey.QueryValue(pszRetStr,_T("home"),&dwCount)==ERROR_SUCCESS)
                {
                MessageBox(pszRetStr,_T("Registry Value"));
                }

                // delete memory allocated to pszRetStr;
                

                if(pszRetStr)
                {
                delete [] pszRetStr;
                pszRetStr=NULL;
                }

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                cheers, Alok Gupta

                M Offline
                M Offline
                Matthew Devine
                wrote on last edited by
                #7

                I was trying to now look up the registry key value of ProxyEnable: This is located in "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", I was trying to edit your code to work with the fact that this is a DWORD. But I can't seem to get it to work, what I want to do is query the value of that key. After I have the value I just want to write a simple if-statement that will execute ProxyOn() method if the Proxy is seen as being enabled and a ProxyOff() method if the proxy is disabled. Any assistance would be greatly appreciated.

                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