|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Rename registry Key [folder/ branch]hello fellows,
does anyone have a code that do the following : Rename registry Key [folder/ branch]. Please, if anyone have a vb.net 2003 code sample 10x in advance Hadar The process of renaming a registry key is actually a recursive copy of all
the values and sub keys and then a delete of the original key. So when you call RenameSubKey it actually calls CopyKey. Imports System Imports System.Collections.Generic Imports System.Text Imports Microsoft.Win32 Namespace RenameRegisTryKey Public Class RegisTryUtilities Public Function RenameSubKey(ByVal parentKey As RegistryKey, ByVal subKeyName As String, ByVal NewSubKeyName As String) As Boolean CopyKey(parentKey, subKeyName, NewSubKeyName) parentKey.DeleteSubKeyTree(subKeyName) Return True End Function Public Function CopyKey(ByVal parentKey As RegistryKey, ByVal keyNameToCopy As String, ByVal NewKeyName As String) As Boolean 'Create new key Dim destinationKey As RegistryKey = parentKey.CreateSubKey(NewKeyName) 'Open the sourceKey we are copying from Dim sourceKey As RegistryKey = parentKey.OpenSubKey(keyNameToCopy) RecurseCopyKey(sourceKey, destinationKey) Return True End Function Private Sub RecurseCopyKey(ByVal sourceKey As RegistryKey, ByVal destinationKey As RegistryKey) 'copy all the values Dim valueName As String For Each valueName In sourceKey.GetValueNames() Dim objValue As Object = sourceKey.GetValue(valueName) Dim valKind As RegistryValueKind = sourceKey.GetValueKind(valueName) destinationKey.SetValue(valueName, objValue, valKind) Next 'For Each subKey 'Create a new subKey in destinationKey 'Call myself Dim sourceSubKeyName As String For Each sourceSubKeyName In sourceKey.GetSubKeyNames() Dim sourceSubKey As RegistryKey = sourceKey.OpenSubKey(sourceSubKeyName) Dim destSubKey As RegistryKey = destinationKey.CreateSubKey(sourceSubKeyName) RecurseCopyKey(sourceSubKey, destSubKey) Next End Sub End Class End Namespace <hadarmor***@gmail.com> wrote in message Show quoteHide quote news:1166962452.458081.26960@n51g2000cwc.googlegroups.com... > hello fellows, > does anyone have a code that do the following : > Rename registry Key [folder/ branch]. > > Please, if anyone have a vb.net 2003 code sample > > 10x in advance > Hadar > Okay I see you need it 1.1. Generics wont work nor will value valuekind. So
here is my best guess. Be careful with this please as I can't really test it here. Imports System Imports System.Text Imports Microsoft.Win32 Namespace RenameRegisTryKey Public Class RegisTryUtilities Public Function RenameSubKey(ByVal parentKey As RegistryKey, ByVal subKeyName As String, ByVal NewSubKeyName As String) As Boolean CopyKey(parentKey, subKeyName, NewSubKeyName) parentKey.DeleteSubKeyTree(subKeyName) Return True End Function Public Function CopyKey(ByVal parentKey As RegistryKey, ByVal keyNameToCopy As String, ByVal NewKeyName As String) As Boolean 'Create new key Dim destinationKey As RegistryKey = parentKey.CreateSubKey(NewKeyName) 'Open the sourceKey we are copying from Dim sourceKey As RegistryKey = parentKey.OpenSubKey(keyNameToCopy) RecurseCopyKey(sourceKey, destinationKey) Return True End Function Private Sub RecurseCopyKey(ByVal sourceKey As RegistryKey, ByVal destinationKey As RegistryKey) 'copy all the values Dim valueName As String For Each valueName In sourceKey.GetValueNames() Dim objValue As Object = sourceKey.GetValue(valueName) ' Dim valKind As Object = sourceKey.GetValue(valueName) destinationKey.SetValue(valueName, objValue) Next 'For Each subKey 'Create a new subKey in destinationKey 'Call myself Dim sourceSubKeyName As String For Each sourceSubKeyName In sourceKey.GetSubKeyNames() Dim sourceSubKey As RegistryKey = sourceKey.OpenSubKey(sourceSubKeyName) Dim destSubKey As RegistryKey = destinationKey.CreateSubKey(sourceSubKeyName) RecurseCopyKey(sourceSubKey, destSubKey) Next End Sub End Class End Namespace <hadarmor***@gmail.com> wrote in message Show quoteHide quote news:1166962452.458081.26960@n51g2000cwc.googlegroups.com... > hello fellows, > does anyone have a code that do the following : > Rename registry Key [folder/ branch]. > > Please, if anyone have a vb.net 2003 code sample > > 10x in advance > Hadar >
Other interesting topics
Goodbye microsoft.public.dotnet.languages.vb
overriding array size How to determine if e-mail was sent OK Add Active Directory Users to a Group on a Workstation regex expressions MySQL and MyOleDB How to get the checked columns in DataGridView Deleting controls Autorun on USB Flash Drive MySQL AND UNICODE |
|||||||||||||||||||||||