CopyKey and RecurseCopyKey  Registry Key copies

' https://www.codeproject.com/articles/16343/copy-and-rename-registry-keys

    Function CopyKey(parentKey As RegistryKey, keyNameToCopy As String, newKeyName As String) As Boolean

        Dim destinationKey As RegistryKey = parentKey.CreateSubKey(newKeyName)

        Dim sourceKey As RegistryKey = parentKey.OpenSubKey(keyNameToCopy)

        subSymbols()

        RecurseCopyKey(sourceKey, destinationKey, 4, 0)

        '         //Open the sourceKey we are copying from

        '         RegistryKey sourceKey = parentKey.OpenSubKey(keyNameToCopy);

        '         RecurseCopyKey(sourceKey, destinationKey);

        sourceKey.Close()

        Return True

    End Function

    Sub RecurseCopyKey(sourceKey As RegistryKey, destinationKey As RegistryKey, iLevelMax As Integer, iCurrentLevel As Integer)

        '//copy all the values

        For Each valuename As String In sourceKey.GetValueNames()

            Dim objValue As Object = sourceKey.GetValue(valuename)

            Dim valKind As RegistryValueKind = sourceKey.GetValueKind(valuename)

            destinationKey.SetValue(valuename, objValue, valKind)

            subSymbols()

        Next

        '         foreach (string valueName in sourceKey.GetValueNames())

        '         {       

        '             Object objValue = sourceKey.GetValue(valueName);

        '             RegistryValueKind valKind = sourceKey.GetValueKind(valueName);

        '             destinationKey.SetValue(valueName, objValue, valKind);

        '         }

        '         //For Each subKey

        '         //Create a New subKey in destinationKey

        '         //Call myself

        For Each sourceSubKeyName As String In sourceKey.GetSubKeyNames()

            Dim sourceSubKey As RegistryKey = sourceKey.OpenSubKey(sourceSubKeyName)

            Dim destSubKey As RegistryKey = destinationKey.CreateSubKey(sourceSubKeyName)

            If iCurrentLevel < iLevelMax Then

                subSymbols()

                RecurseCopyKey(sourceSubKey, destSubKey, iLevelMax, iCurrentLevel + 1)

            End If

            sourceSubKey.Close()

        Next

        '         foreach (string sourceSubKeyName in sourceKey.GetSubKeyNames())

        '         {

        '             RegistryKey sourceSubKey = sourceKey.OpenSubKey(sourceSubKeyName);

        '             RegistryKey destSubKey = destinationKey.CreateSubKey(sourceSubKeyName);

        '             RecurseCopyKey(sourceSubKey, destSubKey);

        '         }

    End Sub

    ' Public bool CopyKey(RegistryKey parentKey,

    'String keyNameToCopy, String newKeyName)

    '     {

    '         //Create New key

    '         RegistryKey destinationKey = parentKey.CreateSubKey(newKeyName);

    '         //Open the sourceKey we are copying from

    '         RegistryKey sourceKey = parentKey.OpenSubKey(keyNameToCopy);

    '         RecurseCopyKey(sourceKey, destinationKey);

    '         Return True;

    '     }

    '     Private void RecurseCopyKey(RegistryKey sourceKey, RegistryKey destinationKey)

    '     {

    '         //copy all the values

    '         foreach (string valueName in sourceKey.GetValueNames())

    '         {       

    '             Object objValue = sourceKey.GetValue(valueName);

    '             RegistryValueKind valKind = sourceKey.GetValueKind(valueName);

    '             destinationKey.SetValue(valueName, objValue, valKind);

    '         }

    '         //For Each subKey

    '         //Create a New subKey in destinationKey

    '         //Call myself

    '         foreach (string sourceSubKeyName in sourceKey.GetSubKeyNames())

    '         {

    '             RegistryKey sourceSubKey = sourceKey.OpenSubKey(sourceSubKeyName);

    '             RegistryKey destSubKey = destinationKey.CreateSubKey(sourceSubKeyName);

    '             RecurseCopyKey(sourceSubKey, destSubKey);

    '         }

    '     }

    ' }