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. Read / Write Registry

Read / Write Registry

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminquestion
7 Posts 2 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.
  • L Offline
    L Offline
    Lucky the code machine
    wrote on last edited by
    #1

    Hiya, Please halp me! I need some code to read & write registry keys in a particular place that already exists: "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" above is the location and then i need to write a new key & read a key. DWord and Edit. Is there a simple way to do this? Thank you for your time. :) An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky

    M 1 Reply Last reply
    0
    • M Martin Ziacek

      There is CRegKey class in the VC++ 6.0 installation somewhere, it is easy to use.

      L Offline
      L Offline
      Lucky the code machine
      wrote on last edited by
      #2

      I dont understand (Sory) How do i get at / read that? An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky

      M 2 Replies Last reply
      0
      • L Lucky the code machine

        Hiya, Please halp me! I need some code to read & write registry keys in a particular place that already exists: "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" above is the location and then i need to write a new key & read a key. DWord and Edit. Is there a simple way to do this? Thank you for your time. :) An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky

        M Offline
        M Offline
        Martin Ziacek
        wrote on last edited by
        #3

        There is CRegKey class in the VC++ 6.0 installation somewhere, it is easy to use.

        L 1 Reply Last reply
        0
        • L Lucky the code machine

          I dont understand (Sory) How do i get at / read that? An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky

          M Offline
          M Offline
          Martin Ziacek
          wrote on last edited by
          #4

          This is declaration of that class: class CRegKey { public: CRegKey(); ~CRegKey(); // Attributes public: operator HKEY() const; HKEY m_hKey; // Operations public: LONG SetValue(DWORD dwValue, LPCTSTR lpszValueName); LONG QueryValue(DWORD& dwValue, LPCTSTR lpszValueName); LONG QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount); LONG QueryValue(BYTE *pbValue, LPCTSTR lpszValueName, DWORD* pdwCount); LONG SetValue(LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); LONG SetValue(BYTE *pbValue, DWORD dwLength, LPCTSTR lpszValueName = NULL); LONG SetKeyValue(LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); static LONG WINAPI SetValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass = REG_NONE, DWORD dwOptions = REG_OPTION_NON_VOLATILE, REGSAM samDesired = KEY_ALL_ACCESS, LPSECURITY_ATTRIBUTES lpSecAttr = NULL, LPDWORD lpdwDisposition = NULL); LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired = KEY_ALL_ACCESS); LONG Close(); HKEY Detach(); void Attach(HKEY hKey); LONG DeleteSubKey(LPCTSTR lpszSubKey); LONG RecurseDeleteKey(LPCTSTR lpszKey); LONG DeleteValue(LPCTSTR lpszValue); }; and you can do this: CRegKey reg; reg.Open(HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Internet Settings"); and then reg.QueryValue(...); //to read value reg.SetValue(...) //to write value

          L 1 Reply Last reply
          0
          • M Martin Ziacek

            Lucky the code machine wrote: Date:13:17 29 May '02 You had posted your answer to my message two minutes before I posted it. :confused:

            L Offline
            L Offline
            Lucky the code machine
            wrote on last edited by
            #5

            Nice! Im in England so i guess something to do with that? :confused: Thanks a lot for that on registrys, i will try that. Looks good. Thanks An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky

            1 Reply Last reply
            0
            • L Lucky the code machine

              I dont understand (Sory) How do i get at / read that? An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky

              M Offline
              M Offline
              Martin Ziacek
              wrote on last edited by
              #6

              Lucky the code machine wrote: Date:13:17 29 May '02 You had posted your answer to my message two minutes before I posted it. :confused:

              L 1 Reply Last reply
              0
              • M Martin Ziacek

                This is declaration of that class: class CRegKey { public: CRegKey(); ~CRegKey(); // Attributes public: operator HKEY() const; HKEY m_hKey; // Operations public: LONG SetValue(DWORD dwValue, LPCTSTR lpszValueName); LONG QueryValue(DWORD& dwValue, LPCTSTR lpszValueName); LONG QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount); LONG QueryValue(BYTE *pbValue, LPCTSTR lpszValueName, DWORD* pdwCount); LONG SetValue(LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); LONG SetValue(BYTE *pbValue, DWORD dwLength, LPCTSTR lpszValueName = NULL); LONG SetKeyValue(LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); static LONG WINAPI SetValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass = REG_NONE, DWORD dwOptions = REG_OPTION_NON_VOLATILE, REGSAM samDesired = KEY_ALL_ACCESS, LPSECURITY_ATTRIBUTES lpSecAttr = NULL, LPDWORD lpdwDisposition = NULL); LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired = KEY_ALL_ACCESS); LONG Close(); HKEY Detach(); void Attach(HKEY hKey); LONG DeleteSubKey(LPCTSTR lpszSubKey); LONG RecurseDeleteKey(LPCTSTR lpszKey); LONG DeleteValue(LPCTSTR lpszValue); }; and you can do this: CRegKey reg; reg.Open(HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Internet Settings"); and then reg.QueryValue(...); //to read value reg.SetValue(...) //to write value

                L Offline
                L Offline
                Lucky the code machine
                wrote on last edited by
                #7

                I hope im not being a pain. I tryed this and it worked fine: char* text; //unsigned long* buffer; DWORD* buffer; unsigned long PerServer; unsigned long Per1_0Server; CRegKey reg; reg.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); reg.QueryValue(PerServer,"MaxConnectionsPerServer"); but when i try to read a string (the windows version name) with: reg.Open(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion"); reg.QueryValue(text,"ProductName",buffer); i get an assertation error on the line "pdwCount!=null;" (in CRegKey) if i change buffer to anything using "buffer=(unsigned long*)999;" i dont get the error but i get no data. Am i being stupid? I cant see where im going wrong. An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky

                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