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. Problem with the registry

Problem with the registry

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminhelptutorialquestion
8 Posts 5 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.
  • J Offline
    J Offline
    Jochem
    wrote on last edited by
    #1

    The problem is that all data that i save in the registry is gone after windows (2000) is restarted. All data appears to be ok after the application closes. But after the restart the key is completely gone. The code used in the app: Opening the key: HKEY hKeyRoot = HKEY_CURRENT_USER; LPCTSTR pszPath = "Software\\Companyname\\My App Name\\Settings" HKEY hKey; DWORD dw; RegCreateKeyEx(hKeyRoot, pszPath, 0L, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw); Writing: int iValue = 8; LPCTSTR pszKey = "MyInteger"; hKey as returned by RegCreateKeyEx RegSetValueEx(hKey, pszKey, 0L, REG_DWORD, (CONST BYTE*)&iValue, sizeof(int)); Does anyone know how to prevent this and why it happens? Thanks I'm smart enough to know that i'm stupid and i'm stupid enough to think that i'm smart

    J R M 4 Replies Last reply
    0
    • J Jochem

      The problem is that all data that i save in the registry is gone after windows (2000) is restarted. All data appears to be ok after the application closes. But after the restart the key is completely gone. The code used in the app: Opening the key: HKEY hKeyRoot = HKEY_CURRENT_USER; LPCTSTR pszPath = "Software\\Companyname\\My App Name\\Settings" HKEY hKey; DWORD dw; RegCreateKeyEx(hKeyRoot, pszPath, 0L, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw); Writing: int iValue = 8; LPCTSTR pszKey = "MyInteger"; hKey as returned by RegCreateKeyEx RegSetValueEx(hKey, pszKey, 0L, REG_DWORD, (CONST BYTE*)&iValue, sizeof(int)); Does anyone know how to prevent this and why it happens? Thanks I'm smart enough to know that i'm stupid and i'm stupid enough to think that i'm smart

      J Offline
      J Offline
      Joan M
      wrote on last edited by
      #2

      you must change the REG_OPTION_VOLATILE to KEY_ALL_ACCESS. Hope this helps...

      J 1 Reply Last reply
      0
      • J Jochem

        The problem is that all data that i save in the registry is gone after windows (2000) is restarted. All data appears to be ok after the application closes. But after the restart the key is completely gone. The code used in the app: Opening the key: HKEY hKeyRoot = HKEY_CURRENT_USER; LPCTSTR pszPath = "Software\\Companyname\\My App Name\\Settings" HKEY hKey; DWORD dw; RegCreateKeyEx(hKeyRoot, pszPath, 0L, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw); Writing: int iValue = 8; LPCTSTR pszKey = "MyInteger"; hKey as returned by RegCreateKeyEx RegSetValueEx(hKey, pszKey, 0L, REG_DWORD, (CONST BYTE*)&iValue, sizeof(int)); Does anyone know how to prevent this and why it happens? Thanks I'm smart enough to know that i'm stupid and i'm stupid enough to think that i'm smart

        R Offline
        R Offline
        Ramu Pulipati
        wrote on last edited by
        #3

        You have to create RegKey using options 'REG_OPTION_NON_VOLATILE' instead of 'REG_OPTION_VOLATILE'. For more details, Check RegCreateKeyEx API in MSDN. If you are developing MFC/ATL based app...you can use CRegKey for easy registry access. Hope this helps. Ramu

        J 1 Reply Last reply
        0
        • J Jochem

          The problem is that all data that i save in the registry is gone after windows (2000) is restarted. All data appears to be ok after the application closes. But after the restart the key is completely gone. The code used in the app: Opening the key: HKEY hKeyRoot = HKEY_CURRENT_USER; LPCTSTR pszPath = "Software\\Companyname\\My App Name\\Settings" HKEY hKey; DWORD dw; RegCreateKeyEx(hKeyRoot, pszPath, 0L, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw); Writing: int iValue = 8; LPCTSTR pszKey = "MyInteger"; hKey as returned by RegCreateKeyEx RegSetValueEx(hKey, pszKey, 0L, REG_DWORD, (CONST BYTE*)&iValue, sizeof(int)); Does anyone know how to prevent this and why it happens? Thanks I'm smart enough to know that i'm stupid and i'm stupid enough to think that i'm smart

          J Offline
          J Offline
          Joan M
          wrote on last edited by
          #4

          this way is how I do it:

          HKEY hKey;
          int iLength = 0;
          CString csPathSubClau = "";

          iLength = csNouValor.GetLength();

          // Obrir la clau requerida.
          csPathSubClau.Format("%s\\%s",m_csPathBase,csSubClau);

          RegOpenKeyEx(HKEY_LOCAL_MACHINE,csPathSubClau,0,KEY_ALL_ACCESS,&hKey);
          RegSetValueEx(hKey,csValor,0,REG_SZ,(BYTE *)csNouValor.GetBuffer(iLength),iLength);

          RegFlushKey(hKey);
          RegCloseKey(hKey);

          1 Reply Last reply
          0
          • J Joan M

            you must change the REG_OPTION_VOLATILE to KEY_ALL_ACCESS. Hope this helps...

            J Offline
            J Offline
            Jochem
            wrote on last edited by
            #5

            The KEY_ALL_ACCESS is the next argument

            A 1 Reply Last reply
            0
            • R Ramu Pulipati

              You have to create RegKey using options 'REG_OPTION_NON_VOLATILE' instead of 'REG_OPTION_VOLATILE'. For more details, Check RegCreateKeyEx API in MSDN. If you are developing MFC/ATL based app...you can use CRegKey for easy registry access. Hope this helps. Ramu

              J Offline
              J Offline
              Jochem
              wrote on last edited by
              #6

              This solves the problem thanks

              1 Reply Last reply
              0
              • J Jochem

                The KEY_ALL_ACCESS is the next argument

                A Offline
                A Offline
                Anonymous
                wrote on last edited by
                #7

                :eek: I must sleep more! sorry...

                1 Reply Last reply
                0
                • J Jochem

                  The problem is that all data that i save in the registry is gone after windows (2000) is restarted. All data appears to be ok after the application closes. But after the restart the key is completely gone. The code used in the app: Opening the key: HKEY hKeyRoot = HKEY_CURRENT_USER; LPCTSTR pszPath = "Software\\Companyname\\My App Name\\Settings" HKEY hKey; DWORD dw; RegCreateKeyEx(hKeyRoot, pszPath, 0L, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw); Writing: int iValue = 8; LPCTSTR pszKey = "MyInteger"; hKey as returned by RegCreateKeyEx RegSetValueEx(hKey, pszKey, 0L, REG_DWORD, (CONST BYTE*)&iValue, sizeof(int)); Does anyone know how to prevent this and why it happens? Thanks I'm smart enough to know that i'm stupid and i'm stupid enough to think that i'm smart

                  M Offline
                  M Offline
                  Michael Dunn
                  wrote on last edited by
                  #8

                  Never use KEY_ALL_ACCESS - only request the access you need. Only admininstrators can open keys with KEY_ALL_ACCESS. --Mike-- I'm bored... Episode I bored. 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

                  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