By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,417 Members | 1,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,417 IT Pros & Developers. It's quick & easy.

Recursive Backup of Registry Key

P: n/a
I am looking for a solution that would allow me to recursively backup a
given registry key that I could then use to import into another machine.
The problem that I keep having is the inability to specify the type of data
in the key and get that data output to screen or file. Specifically
Reg_Binary or Reg_Multi_Sz

Here is just the latest hack that I am working with, most of which is
directly from msdn. Any suggestions or modification that would accomplish
that goal would be appreciated.

Dim RegKey As RegistryKey =
Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentCo ntrolSet\Services\LanmanSe
rver\Shares")

Console.WriteLine("There are {0} subkeys under " & RegKey.Name &
".", _
RegKey.SubKeyCount.ToString())
Console.WriteLine(vbCrLf & "There are {0} values for " & _
"{1}.", RegKey.ValueCount.ToString(), RegKey.Name)

For Each valueName As String In RegKey.GetValueNames()
Console.WriteLine("{0,-8}: {1}", valueName, _
RegKey.GetValue(valueName.tostring))
Next

For Each subKeyName As String In RegKey.GetSubKeyNames()
Dim tempKey As RegistryKey = _
RegKey.OpenSubKey(subKeyName)
Console.WriteLine(vbCrLf & "There are {0} values for " & _
"{1}.", tempKey.ValueCount.ToString(), tempKey.Name)
For Each valueName As String In tempKey.GetValueNames()
Console.WriteLine("{0,-8}: {1}", valueName, _
tempKey.GetValue(valueName.ToString))
Next
Next
End

Thanks in Advance,

Matt
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Matt,

"Matt Brandes" <Ma**********@osca.state.mo.us> schrieb:
I am looking for a solution that would allow me to recursively backup a
given registry key that I could then use to import into another machine.

An easy solution is using "regedit.exe"'s command line options to
export/import registry sections. The following implementation is based on a
VB6 sample written by Thorsten Dörfler [MVP]
(<URL:http://www.google.de/groups?selm=3F7D2DF7.4D9AB5EC%40t-online.de>):

\\\
Public Class RegistryHelper
Public Shared Sub ExportSettings( _
ByVal FileName As String, _
ByVal Section As String _
)
FileName = """" & FileName & """"
Section = """" & Section & """"
Shell( _
"regedit.exe /e " & FileName & " " & Section, _
AppWinStyle.Hide _
)
End Sub

Public Shared Sub ImportSettings( _
ByVal FileName As String, _
Optional ByVal Silent As Boolean = True _
)
FileName = """"& FileName & """"
If Silent Then
FileName = "/s " & FileName
End If
Shell("regedit.exe " & FileName, AppWinStyle.Hide)
End Sub
End Class
///

Keywords: Registry, export, import, section.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

P: n/a
Herfried,

Thanks for the Reply.
I am currently using a similar approach to fire regedit and get the results
to file.

The problem comes in where:
a) Management Wants A Managed Code Solution
b) The application is suppose to be able to exclude specific keys from
being backed up.

I just never thought it would be such a pain to dump a portion of the
registry.

Thanks again,
Matt

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uP*************@TK2MSFTNGP09.phx.gbl...
Matt,

"Matt Brandes" <Ma**********@osca.state.mo.us> schrieb:
I am looking for a solution that would allow me to recursively backup a
given registry key that I could then use to import into another machine.

An easy solution is using "regedit.exe"'s command line options to
export/import registry sections. The following implementation is based on

a VB6 sample written by Thorsten Dörfler [MVP]
(<URL:http://www.google.de/groups?selm=3F7D2DF7.4D9AB5EC%40t-online.de>):

\\\
Public Class RegistryHelper
Public Shared Sub ExportSettings( _
ByVal FileName As String, _
ByVal Section As String _
)
FileName = """" & FileName & """"
Section = """" & Section & """"
Shell( _
"regedit.exe /e " & FileName & " " & Section, _
AppWinStyle.Hide _
)
End Sub

Public Shared Sub ImportSettings( _
ByVal FileName As String, _
Optional ByVal Silent As Boolean = True _
)
FileName = """"& FileName & """"
If Silent Then
FileName = "/s " & FileName
End If
Shell("regedit.exe " & FileName, AppWinStyle.Hide)
End Sub
End Class
///

Keywords: Registry, export, import, section.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

P: n/a
Search the user samples at http://www.gotdotnet.com because I uploaded a
registry key backup utility totally written in VB.NET 2003.

For Mr MVP:

Yes, the code is just a very small part of the program that I wouldn't share
earlier. The only thing that can be done with it is backup a particular key &
its subkeys/values. It doesn't allow the user just to selete only
Registry.LocalMachine for example.

Right, I am off to be. Only a 16-hour day for me today.

"Matt Brandes" wrote:
Herfried,

Thanks for the Reply.
I am currently using a similar approach to fire regedit and get the results
to file.

The problem comes in where:
a) Management Wants A Managed Code Solution
b) The application is suppose to be able to exclude specific keys from
being backed up.

I just never thought it would be such a pain to dump a portion of the
registry.

Thanks again,
Matt

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uP*************@TK2MSFTNGP09.phx.gbl...
Matt,

"Matt Brandes" <Ma**********@osca.state.mo.us> schrieb:
I am looking for a solution that would allow me to recursively backup a
given registry key that I could then use to import into another machine.

An easy solution is using "regedit.exe"'s command line options to
export/import registry sections. The following implementation is based on

a
VB6 sample written by Thorsten Dörfler [MVP]
(<URL:http://www.google.de/groups?selm=3F7D2DF7.4D9AB5EC%40t-online.de>):

\\\
Public Class RegistryHelper
Public Shared Sub ExportSettings( _
ByVal FileName As String, _
ByVal Section As String _
)
FileName = """" & FileName & """"
Section = """" & Section & """"
Shell( _
"regedit.exe /e " & FileName & " " & Section, _
AppWinStyle.Hide _
)
End Sub

Public Shared Sub ImportSettings( _
ByVal FileName As String, _
Optional ByVal Silent As Boolean = True _
)
FileName = """"& FileName & """"
If Silent Then
FileName = "/s " & FileName
End If
Shell("regedit.exe " & FileName, AppWinStyle.Hide)
End Sub
End Class
///

Keywords: Registry, export, import, section.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #4

P: n/a
I can't seem to find that example.
Can you tell me the name of it as they don't allow searching by the
submitter?
"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:26**********************************@microsof t.com...
Search the user samples at http://www.gotdotnet.com because I uploaded a
registry key backup utility totally written in VB.NET 2003.

For Mr MVP:

Yes, the code is just a very small part of the program that I wouldn't share earlier. The only thing that can be done with it is backup a particular key & its subkeys/values. It doesn't allow the user just to selete only
Registry.LocalMachine for example.

Right, I am off to be. Only a 16-hour day for me today.

"Matt Brandes" wrote:
Herfried,

Thanks for the Reply.
I am currently using a similar approach to fire regedit and get the results to file.

The problem comes in where:
a) Management Wants A Managed Code Solution
b) The application is suppose to be able to exclude specific keys from being backed up.

I just never thought it would be such a pain to dump a portion of the
registry.

Thanks again,
Matt

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uP*************@TK2MSFTNGP09.phx.gbl...
Matt,

"Matt Brandes" <Ma**********@osca.state.mo.us> schrieb:
>I am looking for a solution that would allow me to recursively backup a > given registry key that I could then use to import into another machine.

An easy solution is using "regedit.exe"'s command line options to
export/import registry sections. The following implementation is based on
a
VB6 sample written by Thorsten Dörfler [MVP]

(<URL:http://www.google.de/groups?selm=3F7D2DF7.4D9AB5EC%40t-online.de>):
\\\
Public Class RegistryHelper
Public Shared Sub ExportSettings( _
ByVal FileName As String, _
ByVal Section As String _
)
FileName = """" & FileName & """"
Section = """" & Section & """"
Shell( _
"regedit.exe /e " & FileName & " " & Section, _
AppWinStyle.Hide _
)
End Sub

Public Shared Sub ImportSettings( _
ByVal FileName As String, _
Optional ByVal Silent As Boolean = True _
)
FileName = """"& FileName & """"
If Silent Then
FileName = "/s " & FileName
End If
Shell("regedit.exe " & FileName, AppWinStyle.Hide)
End Sub
End Class
///

Keywords: Registry, export, import, section.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #5

P: n/a
"Matt Brandes" <Ma**********@osca.state.mo.us> schrieb:
I can't seem to find that example.
Can you tell me the name of it as they don't allow searching by the
submitter?


I don't know to which of his samples Crouchie is referring, but you can find
a list of his samples here:

<URL:http://www.gotdotnet.com/Community/User/viewprofile.aspx?userid=0003BFFD81B560A3>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.