How do I save and recreate a registry key and its subkeys

Last post 09-23-2011 4:13 by EricC. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 09-23-2011 4:13

    • EricC
    • Not Ranked
    • Joined on 09-23-2011
    • Posts 1

    How do I save and recreate a registry key and its subkeys

     Hello, i am trying to write a simple application to save a registry key and its subkeys and subvalues, and then to restore it once it's deleted from my CE device.

     

    The code is then quite simple:

     

            'Save Registry
            Dim regKey As Microsoft.Win32.RegistryKey = Nothing
            Try
                regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\myApp", False)
                System.IO.File.Delete("\Flash Disk\tmp\savedkeys.txt")
                OpenNETCF.Win32.RegistryHelper.SaveHiveBasedKey(regKey, "\myDir\savedkeys.txt")
                regKey.Close()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try

     

    And then restoring the keys:

            'Restore Reg File
            Try
                OpenNETCF.Win32.RegistryHelper.RestoreHiveBasedKey("\myDir\savedkeys.txt", True)
                MessageBox.Show("Complete")
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try

     

    Unfortunately the second action would always result as an error "unable to restore from specified registry file".

     

    Can anyone help me on this, or indicate me an alternative way to do a registry key restore?

     

    Many Thanks.

    Eric

    Filed under:
Page 1 of 1 (1 items)