Import/Export registry sections as Xml

Exporting registry sections as Xml to simplify registry diffs
Exporting registry sections as Xml to simplify registry diffs

 

The remainder of this article details a tool aimed to import/export registry sections in Xml format, to make registry diff easier in practice.

 

1. Why Xml ?

Although anyone can use the built-in .reg registry export format from regedit, that one is not exactly suited for readability and performing diffs. That's why I decided to come up with a fast-sketched Xml format to play with.

The hierarchical nature of Xml content, in addition to Xml diff tools[^] already available to us makes it an ideal format to work with.

In addition, modern diff tools like Araxis[^] (commercial product) can be used anytime you want your work done finished fast and with strong software.

 

2. Using this tool

2.1 Exporting as Xml

It should be easy to use since basically it mimics the good ol' regedit UI. It would have been smarter to plug the Xml exporter inside regedit, but as far as I know the source code for regedit is not redistributed, I had to rewrite a significant portion of regedit just to make sure I don't end up with a cmdline tool, which would have certainly offended some people out there.

You can select one or more key sections, just like with any multiple selection tree ctrl.

Right-click to export them to the Xml format.

When only one registry section is exported at a time, a default output Xml filename is suggested.

The export process may be quite lengthy in time, of course. But no serious guy would export the whole registry, wouldn't you ? At any moment you may hold the ESCAPE key to abort.

When completed, the resulting standard Xml is automatically open in MSIE.

 

2.2 Importing from Xml

Importing Xml sections to the registry is just as easy. Just select the appropriate menu Option from the File menu. Message boxes will occur whenever the Xml file contains syntax error(s), or if for any reason it wasn't possible to open/create/set a given key or value.

 

2.3 A simple export/import test procedure

Let's just test it by following the steps below :

  • Launch the tool, and expand the HKEY_LOCAL_MACHINE \ System \ Setup key
  • Export it as Xml, by leaving the default name Setup.xml
  • Once the export is finished, IE opens the resulting Xml file. Close it.
  • In any text editor, open this file, and lookup the keyname Setup
  • Replace the keyname with SetupF, so to fake a new key
  • Taking the tool back, select Import from Xml... and load Setup.xml
  • Once the import is finished, press F5 to refresh the tree
  • Expand the key again, and look for the new SetupF key, values and subkeys

 

3. The Xml format

Let's take an example, if you export the HKEY_LOCAL_MACHINE\SYSTEM\Setup key, pictured here :

Exporting the HKEY_LOCAL_MACHINE\SYSTEM\Setup section
Exporting the HKEY_LOCAL_MACHINE\SYSTEM\Setup section

 

you'll get the standard Xml below :
<?xml version="1.0" encoding="UTF-8"?>
 <registry>
  <k name="HKEY_LOCAL_MACHINE">
   <k name="SYSTEM">
    <k name="Setup">
     <v name="CmdLine" value="setup -newsetup"/>
     <v name="OsLoaderPath" value="\"/>
     <v name="SetupType" value="0x00000000 (0)" type="REG_DWORD"/>
     <v name="SystemPartition" value="\Device\HarddiskVolume1"/>
     <v name="SystemPrefix" value="cf 03 00 00 00 a0 3d e0" type="REG_BINARY"/>
     <v name="SystemSetupInProgress" value="0x00000000 (0)" type="REG_DWORD"/>
     <k name="AllowStart">
      <k name="AFD"/>
      <k name="EventLog"/>
      <k name="PlugPlay"/>
      <k name="ProtectedStorage"/>
      <k name="Rpcss"/>
      <k name="SamSs"/>
      <k name="Seclogon"/>
      <k name="WS2IFSL"/>
     </k>
    </k>
   </k>
  </k>
 </registry>

I have created a straight forward Xml format. k stands for key, and v for value. Values have a type attribute whenever it's not a string. The shared source code is not rocket science but there's a generic writer, and a generic reader, which you can easily reuse for your own needs.

Update history :

  • Oct 27 : code complete. Ability to export one or more registry sections
  • Nov 02 : Ability to import registry sections as well.

 

 

Stephane Rodriguez - Nov 2, 2002.

 


Home
Blog