none
RegistryHive value from hive name RRS feed

  • Question

  • Hi All,

    Is there any method to get RegistryHive enumeration value if I have the corresponding hive name string.

    For example, for the hive name string "HKEY_CLASSES_ROOT", I need to get the value RegistryHive.ClassesRoot

    Wednesday, September 12, 2018 9:08 AM

Answers

  • Hi SQLNeophyte,

    As far as I know, it seems that .net framework does not provide a method to achieve it, you could write a custom method to retrieve related RegistryHive via key name, like this:

    public RegistryHive GetRegistryHive(string keyName)
    {
                RegistryHive registryHive = RegistryHive.ClassesRoot;
                switch (keyName)
                {
                    case "HKEY_CLASSES_ROOT":
                        registryHive = RegistryHive.ClassesRoot;
                        break;
                    case "HKEY_CURRENT_USER":
                        registryHive = RegistryHive.CurrentUser;
                        break;
    //others
                    default :
                        registryHive = RegistryHive.ClassesRoot;
                        break;
    
                }
    
                return registryHive;
    }

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by CoolDadTxModerator Thursday, September 13, 2018 1:53 PM
    • Marked as answer by SQLNeophyte Monday, September 17, 2018 9:36 AM
    Thursday, September 13, 2018 8:11 AM
    Moderator

All replies

  • Take a look at these examples

    Let us know if it helps

     

    Thanks,
    Vivek Bansod
    Blog | MSDN | LinkedIn
     

    Wednesday, September 12, 2018 12:04 PM
  • Why do you need to do this? The RegistryHive stuff is just a shortcut for getting to the actual key, not really the other way around. 

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, September 12, 2018 1:50 PM
    Moderator
  • Take a look at these examples

    Let us know if it helps

     

    Thanks,
    Vivek Bansod
    Blog | MSDN | LinkedIn
     

    I have gone through the examples in the link and didn't find a method to convert registry hive name to RegistryHive type
    Thursday, September 13, 2018 5:14 AM
  • Take a look at these examples

    Let us know if it helps

     

    Thanks,
    Vivek Bansod
    Blog | MSDN | LinkedIn
     

    I have gone through the examples in the link and didn't find a method to convert registry hive name to RegistryHive type

    I have a command line application which calls a function that takes an argument of type RegistryHive. When calling this function, I will pass the value which I accept from user for this parameter. I plan to accept the value from user as command line argument. The command line argument will be specified with the registry hive name like "HKEY_CLASSES_ROOT". So I receive this in code as a string. Now I have to convert it to the corresponding RegistryHive type before passing to the function. I plan to input the parameter as hive name(ie HKEY_CLASSES_ROOT etc) since it gives more clarity to the user. Hope it is clear.

    Thursday, September 13, 2018 5:20 AM
  • Hi SQLNeophyte,

    As far as I know, it seems that .net framework does not provide a method to achieve it, you could write a custom method to retrieve related RegistryHive via key name, like this:

    public RegistryHive GetRegistryHive(string keyName)
    {
                RegistryHive registryHive = RegistryHive.ClassesRoot;
                switch (keyName)
                {
                    case "HKEY_CLASSES_ROOT":
                        registryHive = RegistryHive.ClassesRoot;
                        break;
                    case "HKEY_CURRENT_USER":
                        registryHive = RegistryHive.CurrentUser;
                        break;
    //others
                    default :
                        registryHive = RegistryHive.ClassesRoot;
                        break;
    
                }
    
                return registryHive;
    }

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by CoolDadTxModerator Thursday, September 13, 2018 1:53 PM
    • Marked as answer by SQLNeophyte Monday, September 17, 2018 9:36 AM
    Thursday, September 13, 2018 8:11 AM
    Moderator
  • Hi SQLNeophyte,

    As far as I know, it seems that .net framework does not provide a method to achieve it, you could write a custom method to retrieve related RegistryHive via key name, like this:

    public RegistryHive GetRegistryHive(string keyName)
    {
                RegistryHive registryHive = RegistryHive.ClassesRoot;
                switch (keyName)
                {
                    case "HKEY_CLASSES_ROOT":
                        registryHive = RegistryHive.ClassesRoot;
                        break;
                    case "HKEY_CURRENT_USER":
                        registryHive = RegistryHive.CurrentUser;
                        break;
    //others
                    default :
                        registryHive = RegistryHive.ClassesRoot;
                        break;
    
                }
    
                return registryHive;
    }

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Hi Zhanglong Wu,

    Thank you for the information. So I am going ahead with that assumption. Thanks all for the support..

    Monday, September 17, 2018 9:36 AM