Search code examples
vb.nettypesregistrydword

Find registry value types in VB.Net


I am creating a very basic registry viewer in VB.Net. I need to find the type of registry key (String, DWORD, Binary .etc) but I dont know how to using VB.Net and I cannot find an answer anywhere. http://s22.postimg.org/98acwiz01/Capture.png Here is a picture of what I am trying to do. On line 7, I am trying to get the type of registry value it is. You can see I've tried and failed miserably. Please help me :)


Solution

  • You can use the GetValueKind() method of the RegistryKey class to retrieve the data type of the value. RegistryKey is part of the Microsoft.Win32 namespace. For example:

        Dim subKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion")
        Dim type As RegistryValueKind = subkey.GetValueKind("ProgramFilesDir")
    

    The Registry class has a number of static fields which give access to the base keys. For example, Registry.CurrentConfig gives access to the keys under HKEY_CURRENT_CONFIG. There are seven of these different starting points so to get the type of any specified key you will need to check the start of the key name and use the appropriate starting point. You can then specify the rest of the key in the OpenSubKey() call remembering to escape the backslashes.