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. How to change the default registry root

How to change the default registry root

Scheduled Pinned Locked Moved C / C++ / MFC
windows-admintutorial
12 Posts 4 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.
  • S Offline
    S Offline
    Sarvan AL
    wrote on last edited by
    #1

    Hi Geniuses, I saving the toolbar status of my MDI application using SaveBarState (_T("TBStatus")). It works fine. It stores the status in the registry here: HKEY_CURRENT_USER\Software\Local AppWizard-Generated Applications\MyApp\TBStatus

    I want the status to be stored in some other place, specifically here:
    HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication\TBStatus

    Where "HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication" is the installation entry.

    My aim is to remove the toolbar status entry from the registry while uninstalling the application.

    If anybody could suggest me a solution, I would be grateful. Thanks in advance, Sarvan AL

    N G 2 Replies Last reply
    0
    • S Sarvan AL

      Hi Geniuses, I saving the toolbar status of my MDI application using SaveBarState (_T("TBStatus")). It works fine. It stores the status in the registry here: HKEY_CURRENT_USER\Software\Local AppWizard-Generated Applications\MyApp\TBStatus

      I want the status to be stored in some other place, specifically here:
      HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication\TBStatus

      Where "HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication" is the installation entry.

      My aim is to remove the toolbar status entry from the registry while uninstalling the application.

      If anybody could suggest me a solution, I would be grateful. Thanks in advance, Sarvan AL

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      Take a look at SetRegistryKey(...).


      Nibu thomas Software Developer Faqs by Michael dunn

      S 1 Reply Last reply
      0
      • N Nibu babu thomas

        Take a look at SetRegistryKey(...).


        Nibu thomas Software Developer Faqs by Michael dunn

        S Offline
        S Offline
        Sarvan AL
        wrote on last edited by
        #3

        Hi Nibu, The SetRegistryKey always stores under "HKEY_CURRENT_USER\Software". But I want to store in "HKEY_LOCAL_MACHINE\SOFTWARE\MyApp". I am using Win2000. But it needs to be done in Win98 and WinXP too. Is there anyother alternative? Thanks for your interest. Sarvan AL

        M N 2 Replies Last reply
        0
        • S Sarvan AL

          Hi Nibu, The SetRegistryKey always stores under "HKEY_CURRENT_USER\Software". But I want to store in "HKEY_LOCAL_MACHINE\SOFTWARE\MyApp". I am using Win2000. But it needs to be done in Win98 and WinXP too. Is there anyother alternative? Thanks for your interest. Sarvan AL

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

          Unless you have a specific need, the toolbar state shouldn't be stored in HKLM, since the UI state is a per-user thing.

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          1 Reply Last reply
          0
          • S Sarvan AL

            Hi Nibu, The SetRegistryKey always stores under "HKEY_CURRENT_USER\Software". But I want to store in "HKEY_LOCAL_MACHINE\SOFTWARE\MyApp". I am using Win2000. But it needs to be done in Win98 and WinXP too. Is there anyother alternative? Thanks for your interest. Sarvan AL

            N Offline
            N Offline
            Nibu babu thomas
            wrote on last edited by
            #5

            Sarvan AL wrote:

            Is there anyother alternative?

            From the Docs: If you assign a value to m_pszRegistryKey, it must be dynamically allocated on the heap. The CWinApp destructor calls free( ) with this pointer. You many want to use the _tcsdup( ) run-time library function to do the allocating. Also, free the memory associated with the current pointer before assigning a new value. For example:

            //First free the string allocated by MFC at CWinApp startup.
            //The string is allocated before InitInstance is called.
            free((void*)m_pszRegistryKey);
            //Change the name of the registry key.
            //The CWinApp destructor will free the memory.
            m_pszRegistryKey=_tcsdup(_T(“HKEY_CURRENT_USER\\Software\\mycompany\\myapp\\thissection\\thisvalue”));


            Nibu thomas Software Developer Faqs by Michael dunn

            S 1 Reply Last reply
            0
            • S Sarvan AL

              Hi Geniuses, I saving the toolbar status of my MDI application using SaveBarState (_T("TBStatus")). It works fine. It stores the status in the registry here: HKEY_CURRENT_USER\Software\Local AppWizard-Generated Applications\MyApp\TBStatus

              I want the status to be stored in some other place, specifically here:
              HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication\TBStatus

              Where "HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication" is the installation entry.

              My aim is to remove the toolbar status entry from the registry while uninstalling the application.

              If anybody could suggest me a solution, I would be grateful. Thanks in advance, Sarvan AL

              G Offline
              G Offline
              Ganesh_T
              wrote on last edited by
              #6

              Use RegCreateKey to creaet the key under any root. Just you have to specify HKLM_LOCAL_MACHINE and other parameters You can set values by RegSetValue or RegSetValueEx Cab get value by : RegQueryValue or RegQueryValueEx. you can ermove entry by RegDeleteKey and RegDeleteValue. Cheers "Peace of mind through Technology"

              1 Reply Last reply
              0
              • N Nibu babu thomas

                Sarvan AL wrote:

                Is there anyother alternative?

                From the Docs: If you assign a value to m_pszRegistryKey, it must be dynamically allocated on the heap. The CWinApp destructor calls free( ) with this pointer. You many want to use the _tcsdup( ) run-time library function to do the allocating. Also, free the memory associated with the current pointer before assigning a new value. For example:

                //First free the string allocated by MFC at CWinApp startup.
                //The string is allocated before InitInstance is called.
                free((void*)m_pszRegistryKey);
                //Change the name of the registry key.
                //The CWinApp destructor will free the memory.
                m_pszRegistryKey=_tcsdup(_T(“HKEY_CURRENT_USER\\Software\\mycompany\\myapp\\thissection\\thisvalue”));


                Nibu thomas Software Developer Faqs by Michael dunn

                S Offline
                S Offline
                Sarvan AL
                wrote on last edited by
                #7

                Hi Nibu, Changing "m_pszRegistryKey" value, remains under the hierarchy "HKEY_CURRENT_USER\Software\". If I set this member variable with "HKEY_CURRENT_USER\\Software\\mycompany", the toolbar status is here: HKEY_CURRENT_USER\\Software\\HKEY_CURRENT_USER\\Software\\mycompany It not at all changing the root. It has same functionality of SetRegistryKey(..). Kindly suggest me a path to go ahead. Sarvan AL

                N 1 Reply Last reply
                0
                • S Sarvan AL

                  Hi Nibu, Changing "m_pszRegistryKey" value, remains under the hierarchy "HKEY_CURRENT_USER\Software\". If I set this member variable with "HKEY_CURRENT_USER\\Software\\mycompany", the toolbar status is here: HKEY_CURRENT_USER\\Software\\HKEY_CURRENT_USER\\Software\\mycompany It not at all changing the root. It has same functionality of SetRegistryKey(..). Kindly suggest me a path to go ahead. Sarvan AL

                  N Offline
                  N Offline
                  Nibu babu thomas
                  wrote on last edited by
                  #8

                  The root is hard coded. So it will be fixed. One option is to override the GetAppRegistryKey function of CWinApp. The root key is hard coded here. So overriding it and returning a valid key (i.e. your key) will help. Note: From here on this will be the default key for the application. The function signature is as follows:

                  HKEY GetAppRegistryKey();

                  This is the function that returns the valid key to the application. Only problem being that it's not a virtual function. :( So if you start using it from a derived class casted to a base class it won't work. So calls like AfxGetApp()->WriteProfileString(...) won't work as it will call CWinApp implementation. Cast it to appropriate class and use it.


                  Nibu thomas Software Developer Faqs by Michael dunn

                  S 1 Reply Last reply
                  0
                  • N Nibu babu thomas

                    The root is hard coded. So it will be fixed. One option is to override the GetAppRegistryKey function of CWinApp. The root key is hard coded here. So overriding it and returning a valid key (i.e. your key) will help. Note: From here on this will be the default key for the application. The function signature is as follows:

                    HKEY GetAppRegistryKey();

                    This is the function that returns the valid key to the application. Only problem being that it's not a virtual function. :( So if you start using it from a derived class casted to a base class it won't work. So calls like AfxGetApp()->WriteProfileString(...) won't work as it will call CWinApp implementation. Cast it to appropriate class and use it.


                    Nibu thomas Software Developer Faqs by Michael dunn

                    S Offline
                    S Offline
                    Sarvan AL
                    wrote on last edited by
                    #9

                    Hi Nibu, Since I am a newbie to Windows Registry Handling, I am not able to grasp the things exactly. If you could explain me in detail, I'd be grateful. I'd like to know, what is happening behind HKCU and HKLM. Is it very hard to make the UI settings common to all the users? Thanks for spending your precious time for me. Sarvan AL

                    N 1 Reply Last reply
                    0
                    • S Sarvan AL

                      Hi Nibu, Since I am a newbie to Windows Registry Handling, I am not able to grasp the things exactly. If you could explain me in detail, I'd be grateful. I'd like to know, what is happening behind HKCU and HKLM. Is it very hard to make the UI settings common to all the users? Thanks for spending your precious time for me. Sarvan AL

                      N Offline
                      N Offline
                      Nibu babu thomas
                      wrote on last edited by
                      #10

                      Sarvan AL wrote:

                      Since I am a newbie to Windows Registry Handling

                      Then it's trouble. You'll have to learn first. Coz registry is very sensitive to changes. Any wrong action is catastrophic. It could take the entire OS down.

                      Sarvan AL wrote:

                      I am not able to grasp the things exactly

                      Only in the beginning.

                      Sarvan AL wrote:

                      I'd like to know, what is happening behind HKCU and HKLM.

                      Nothing special is going on.

                      Sarvan AL wrote:

                      Is it very hard to make the UI settings common to all the users?

                      Not at all. But first learn how to work with the registry. Microsoft has provided this set of functions(WriteProfileString is one of them) so that users don't have to break their head writing and reading values from the registry. There are some easy functions for manipulation of registry. Look at what Ganesh said. All the best.


                      Nibu thomas Software Developer Faqs by Michael dunn

                      S 1 Reply Last reply
                      0
                      • N Nibu babu thomas

                        Sarvan AL wrote:

                        Since I am a newbie to Windows Registry Handling

                        Then it's trouble. You'll have to learn first. Coz registry is very sensitive to changes. Any wrong action is catastrophic. It could take the entire OS down.

                        Sarvan AL wrote:

                        I am not able to grasp the things exactly

                        Only in the beginning.

                        Sarvan AL wrote:

                        I'd like to know, what is happening behind HKCU and HKLM.

                        Nothing special is going on.

                        Sarvan AL wrote:

                        Is it very hard to make the UI settings common to all the users?

                        Not at all. But first learn how to work with the registry. Microsoft has provided this set of functions(WriteProfileString is one of them) so that users don't have to break their head writing and reading values from the registry. There are some easy functions for manipulation of registry. Look at what Ganesh said. All the best.


                        Nibu thomas Software Developer Faqs by Michael dunn

                        S Offline
                        S Offline
                        Sarvan AL
                        wrote on last edited by
                        #11

                        Hi Nibu, I really agree with you. As you said, Windows Registry is very sensitive. That's why I didn't want to do anything trial and error. Let me learn the basics first. Thanks for your suggestion. Sarvan AL

                        N 1 Reply Last reply
                        0
                        • S Sarvan AL

                          Hi Nibu, I really agree with you. As you said, Windows Registry is very sensitive. That's why I didn't want to do anything trial and error. Let me learn the basics first. Thanks for your suggestion. Sarvan AL

                          N Offline
                          N Offline
                          Nibu babu thomas
                          wrote on last edited by
                          #12

                          Sarvan AL wrote:

                          Let me learn the basics first.

                          Great! It's very easy. I would recommend open up the registry and see what is inside and understand why it is there.

                          Sarvan AL wrote:

                          As you said, Windows Registry is very sensitive.

                          Yes it is! But it's a safe approach to use WriteProfileString,... and others in that group.

                          Sarvan AL wrote:

                          That's why I didn't want to do anything trial and error.

                          Never! **First Back Up** :)


                          Nibu thomas Software Developer Faqs by Michael dunn

                          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