Recursive Backup of Registry Key

M

Matt Brandes

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\CurrentControlSet\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
 
H

Herfried K. Wagner [MVP]

Matt,

Matt Brandes said:
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/[email protected]>):

\\\
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

Matt Brandes

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
 
G

Guest

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.
 
M

Matt Brandes

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?
 
G

Guest

Soory people for mis informing you. I deleted two examples (e-mail backup
program for Outlook/Outlook Express was one I know for sure) from my user
samples & I guess that must have been the other one. I will upload it to the
gotdotnet website again, but it probably won't appear until Wednesday at the
earliest.

There is one other project on that site that I done 99.9% of the work on & I
let someone else upload it. It decodes Windows Product ID's & MS Office etc.

You can also view my workspace in which I am helping to develop a
spyware/adware/mailware program.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top