473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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

Dec 24 '06 #1
2 7266
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

<ha*********@gmail.comwrote in message
news:11*********************@n51g2000cwc.googlegro ups.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

Dec 24 '06 #2
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
<ha*********@gmail.comwrote in message
news:11*********************@n51g2000cwc.googlegro ups.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

Dec 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brent Shire | last post by:
To anyone who is willing and able to help me! I have developed a Windows application in VB .NET and wish to deploy it from a CD using a typical install program. I have created a deployment...
2
by: Daniel Bass | last post by:
I've found this article on how to get ASP.Net to read/write from the server's registry, but it got heavily critted as being something that you should not do... ...
1
by: Jay at SCA | last post by:
I've been having the following issue with a windows service I've created in vb.net (.net fw 1.1): Basically, my service monitors a folder for the creation of any new files of a particular type...
3
by: Erik Foreman | last post by:
I am using a folderbrowserdialog object to prowse to a folder then once in that folder I am going to have my program rename all of the files in that folder. I know the rename funchtion but I am not...
6
by: shuaishuaiyes | last post by:
Hello everyone... I'm a Chinese student and my English is very poor...So excuse me if I make grammar mistake. I want to ask some questions about "rename". I'm a beginner, so my C ..... :) I...
1
by: projectVBA | last post by:
Hi , I wrote some add in for PowerPoint and i'm trying to find an automatic way to load it every time PowerPoint starts. I found Microsoft Code example (see below ) BUT the problem is : I can't...
0
by: aris1234 | last post by:
how to rename file name in DB..??? this my code, but this code only save image to folder, can't rename file in DB : <?php //Сheck that we have a file $folder = "../property/$spid";...
1
by: keerthisreenu | last post by:
hai to all..!!! i am facing a problem with mov(....) in c#. i want to rename a folder with the code. iam using mov command. its working. but if i want to rename the folder to capital letters,...
2
by: tanichka | last post by:
Hello you helpful folk! Please look at my script and tell me what I am doing wrong! I am cleaning the names of my music files from unnecessary symbols, and the cleaning works fine, however the perl...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.