RegistryKey

RegistryKey


Represents a key level node inside the Windows Registry.


Implements:

IObject 

Public:

Types:

NameDescription
 RegistryValueKind The value types that can be set and retrieved from the Registry.  
 RegistryValueOptions 

Properties:

NameDescription
 Name (get) Returns the name of the key.  
 SubKeyCount (get) Returns the number of SubKeys within the current key.  
 ValueCount (get) Returns the number of values within the current key.  

Methods:

NameDescription
 CloseKey Closes the RegistryKey object.  
 CreateSubKey Creates a new Windows Registry node.  
 DeleteSubKey Deletes a node from the Windows Registry.  
 DeleteSubKeyTree Deletes all SubKeys within the specified SubKey to delete.  
 DeleteValue Deletes the value from the registry.  
 Equals Returns a boolean indicating if the value and this object instance are the same instance.  
 Flush Flushes any changes to the Windows Registry back to disk.  
 GetHashCode Returns a pseudo-unique number identifying this instance.  
 GetLastWriteTime Returns the last time the subkey was written to.  
 GetSubKeyNames Returns a list of SubKey names within the current SubKey.  
 GetValue Returns the value of a key within a SubKey.  
 GetValueKind Returns the type of value stored in the registry.  
 GetValueNames Returns a list of value names within the current SubKey.  
 OpenSubKey Returns a RegistryKey of the requested SubKey with the write permission specified.  
 SetValue Sets the value of a key value within the SubKey.  
 ToString Returns a string representation of this object instance.  

Remarks

This class allows for easy access and manipulation of keys and key values within the Windows Registry. By using a key naming convention similar to folders the keys and values can be traversed and modified.

There a set of Root nodes that separate the Registry to common areas for specific needs. The Root nodes are the starting place for any keys in the registry. A key name could look like HKEY_LOCAL_MACHINE\Software'.

 Iterate the values found in a registry key.

 Private Sub Main()
     Dim rk As RegistryKey
     Dim names() As String
     Dim i As Long

     ' Open a registry subkey for enumeration.
     Set rk = Registry.LocalMachine.OpenSubKey("software\microsoft\windows\currentversion\run")

     ' Retrieve all names for the values in the key.
     names = rk.GetValueNames

     ' enumerate the names and get the value for each,
     ' displaying the pair as [name] = [value].
     For i = 0 To UBound(names)
         Console.WriteLine "{0} = {1}", names(i), rk.GetValue(names(i))
     Next i

     ' Close the registry key.
     rk.CloseKey

     ' Wait for user to hit return.
     Console.ReadLine
 End Sub

 'This code produces the following output.
 'The list will vary from machine to machine.

 'CplBCL50 = C:\Program Files\EzButton\CplBCL50.EXE
 'ccApp = "C:\Program Files\Common Files\Symantec Shared\ccApp.exe"
 'Symantec NetDriver Monitor = C:\PROGRA~1\SYMNET~1\SNDMon.exe
 

See Also

Project CorLib Overview

Class RegistryKey Overview

Registry

RegistryKeyStatic