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. .NET (Core and Framework)
  4. Registry Manipulation - Odd behaviour

Registry Manipulation - Odd behaviour

Scheduled Pinned Locked Moved .NET (Core and Framework)
windows-admintestingquestiondiscussion
11 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.
  • T Offline
    T Offline
    Tristan Rhodes
    wrote on last edited by
    #1

    Hi Guys, I've got a little wrapper class that exposes some registry properties in my code. This works and passes the unit test for writing and reading the value and comparing the result. However, when i look in the registry, there's no section for the values i am manipulating.

        public static void SetGroupRegInfo(string group, string key, string value)
        {
            RegistryKey rkApp = Registry.LocalMachine.CreateSubKey(
                        REGISTRY\_MICA\_GROUPS + "\\\\" + group,
                        RegistryKeyPermissionCheck.ReadWriteSubTree);
    
            try
            {
                rkApp.SetValue(key, value);
            }
            finally
            {
                rkApp.Close();
            }
        }
    
        public static string GetGroupRegInfo(string group, string key)
        {
            RegistryKey rkApp = Registry.LocalMachine.OpenSubKey(
                                    REGISTRY\_MICA\_GROUPS + "\\\\" + group,
                                    RegistryKeyPermissionCheck.ReadSubTree,
                                    RegistryRights.QueryValues);
    
            if (rkApp == null)
                return null;
    
            try
            {
                return (string)rkApp.GetValue(key);
            }
            finally
            {
                rkApp.Close();
            }
        }
    

    The base registry entries are created correctly by the application installer, but these values just don't seem to appear. Any thoughts? Regards Tris

    ------------------------------- Carrier Bags - 21st Century Tumbleweed.

    L L 2 Replies Last reply
    0
    • T Tristan Rhodes

      Hi Guys, I've got a little wrapper class that exposes some registry properties in my code. This works and passes the unit test for writing and reading the value and comparing the result. However, when i look in the registry, there's no section for the values i am manipulating.

          public static void SetGroupRegInfo(string group, string key, string value)
          {
              RegistryKey rkApp = Registry.LocalMachine.CreateSubKey(
                          REGISTRY\_MICA\_GROUPS + "\\\\" + group,
                          RegistryKeyPermissionCheck.ReadWriteSubTree);
      
              try
              {
                  rkApp.SetValue(key, value);
              }
              finally
              {
                  rkApp.Close();
              }
          }
      
          public static string GetGroupRegInfo(string group, string key)
          {
              RegistryKey rkApp = Registry.LocalMachine.OpenSubKey(
                                      REGISTRY\_MICA\_GROUPS + "\\\\" + group,
                                      RegistryKeyPermissionCheck.ReadSubTree,
                                      RegistryRights.QueryValues);
      
              if (rkApp == null)
                  return null;
      
              try
              {
                  return (string)rkApp.GetValue(key);
              }
              finally
              {
                  rkApp.Close();
              }
          }
      

      The base registry entries are created correctly by the application installer, but these values just don't seem to appear. Any thoughts? Regards Tris

      ------------------------------- Carrier Bags - 21st Century Tumbleweed.

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      I find your post confusing. You say the Unit Tests pass but we have no idea what is being tested. You say "it works" but the value is not in the registry so I have no idea what "it works" means because to me if the value is not written to the registry then I would say it is NOT working.

      L T 2 Replies Last reply
      0
      • T Tristan Rhodes

        Hi Guys, I've got a little wrapper class that exposes some registry properties in my code. This works and passes the unit test for writing and reading the value and comparing the result. However, when i look in the registry, there's no section for the values i am manipulating.

            public static void SetGroupRegInfo(string group, string key, string value)
            {
                RegistryKey rkApp = Registry.LocalMachine.CreateSubKey(
                            REGISTRY\_MICA\_GROUPS + "\\\\" + group,
                            RegistryKeyPermissionCheck.ReadWriteSubTree);
        
                try
                {
                    rkApp.SetValue(key, value);
                }
                finally
                {
                    rkApp.Close();
                }
            }
        
            public static string GetGroupRegInfo(string group, string key)
            {
                RegistryKey rkApp = Registry.LocalMachine.OpenSubKey(
                                        REGISTRY\_MICA\_GROUPS + "\\\\" + group,
                                        RegistryKeyPermissionCheck.ReadSubTree,
                                        RegistryRights.QueryValues);
        
                if (rkApp == null)
                    return null;
        
                try
                {
                    return (string)rkApp.GetValue(key);
                }
                finally
                {
                    rkApp.Close();
                }
            }
        

        The base registry entries are created correctly by the application installer, but these values just don't seem to appear. Any thoughts? Regards Tris

        ------------------------------- Carrier Bags - 21st Century Tumbleweed.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, I would guess you're running on Vista or higher, which virtualizes all registry hives but current_user when running below elevated admin level, whereas your installer (and your unit tests?) probably runs as elevated admin and creates and uses the proper keys. A regular user is not supposed to modify local_machine keys, since they extend beyond his realm. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        T 1 Reply Last reply
        0
        • L led mike

          I find your post confusing. You say the Unit Tests pass but we have no idea what is being tested. You say "it works" but the value is not in the registry so I have no idea what "it works" means because to me if the value is not written to the registry then I would say it is NOT working.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          can't stay away for more than 8 minutes, can you? :laugh:

          Luc Pattyn [Forum Guidelines] [My Articles]


          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


          L 1 Reply Last reply
          0
          • L Luc Pattyn

            can't stay away for more than 8 minutes, can you? :laugh:

            Luc Pattyn [Forum Guidelines] [My Articles]


            The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


            L Offline
            L Offline
            led mike
            wrote on last edited by
            #5

            Luc Pattyn wrote:

            can't stay away for more than 8 minutes, can you?

            Hey Luc, See here[^] and here[^] So long dude. :beer:

            L 1 Reply Last reply
            0
            • L led mike

              Luc Pattyn wrote:

              can't stay away for more than 8 minutes, can you?

              Hey Luc, See here[^] and here[^] So long dude. :beer:

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Exactly, that[^] and your above message are 8 minutes apart. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


              L 1 Reply Last reply
              0
              • L Luc Pattyn

                Exactly, that[^] and your above message are 8 minutes apart. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                L Offline
                L Offline
                led mike
                wrote on last edited by
                #7

                Luc Pattyn wrote:

                and your above message are 8 minutes apart.

                That time is the original post, I modified it twice, see where I say "I just changed my mind". ;)

                L 1 Reply Last reply
                0
                • L led mike

                  Luc Pattyn wrote:

                  and your above message are 8 minutes apart.

                  That time is the original post, I modified it twice, see where I say "I just changed my mind". ;)

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  I see. I never mind the "modified at..." message that gets added automatically, it uses Bujumbura local time or something similar, doesn't tell me much. In the mean time, you're still here. Which is great. BTW: if and when the new be-really-kind rules would really cripple you, you can always put a leaded answer in one of the soapboxes/back rooms, and just reply with a link to it. :-D

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                  1 Reply Last reply
                  0
                  • L led mike

                    I find your post confusing. You say the Unit Tests pass but we have no idea what is being tested. You say "it works" but the value is not in the registry so I have no idea what "it works" means because to me if the value is not written to the registry then I would say it is NOT working.

                    T Offline
                    T Offline
                    Tristan Rhodes
                    wrote on last edited by
                    #9

                    Well, "it works" would mean that the unit test does the following: * Write a value to the registry via the wrapper * Read a value from the registry via the wrapper * Assert that the value read is equal to the value written So the fact that these values don't appear in the registry confuses me too and I'm inclined to agree that it appears to be not working, hence i posted here. :P

                    ------------------------------- Carrier Bags - 21st Century Tumbleweed.

                    1 Reply Last reply
                    0
                    • L Luc Pattyn

                      Hi, I would guess you're running on Vista or higher, which virtualizes all registry hives but current_user when running below elevated admin level, whereas your installer (and your unit tests?) probably runs as elevated admin and creates and uses the proper keys. A regular user is not supposed to modify local_machine keys, since they extend beyond his realm. :)

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                      T Offline
                      T Offline
                      Tristan Rhodes
                      wrote on last edited by
                      #10

                      Yes, I'm on vista. What effect will this have if i shutdown and re-start? Does the registry for my local machine get burned? Is there any way around this without admin rights?

                      ------------------------------- Carrier Bags - 21st Century Tumbleweed.

                      L 1 Reply Last reply
                      0
                      • T Tristan Rhodes

                        Yes, I'm on vista. What effect will this have if i shutdown and re-start? Does the registry for my local machine get burned? Is there any way around this without admin rights?

                        ------------------------------- Carrier Bags - 21st Century Tumbleweed.

                        L Offline
                        L Offline
                        Luc Pattyn
                        wrote on last edited by
                        #11

                        Tristan Rhodes wrote:

                        without admin rights?

                        use current_user. :)

                        Luc Pattyn [Forum Guidelines] [My Articles]


                        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                        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