Introduction

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 :

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

Comments and Discussions

Instead of having a v element for each k element with the value attribute set to "(value not set)" you could add an optional value attribute for the k element that contains the (default) value for the key.

For example:

<registry><kname="key name1"value="value for the key if other than default"/><kname="key name2"/></registry>

Instead of:

<registry><kname="key name1"><vname="(default)"value="value for the key if other than default"/></k><kname="key name2"><vname="(default)"value="(value not set)"/></k></registry>

Although that's a nice idea, I won't give it any chance to live it any longer.

That said, you have the code. Feel free yo update it on your own.

If you use the standard Xml output, then semantically speaking k is for keys, and v for values. Readability looks somewhat better by putting a value in a key tag, but what now if I want to filter out all keys or all values ?

If you use the faked Xml (which is honestly my preferred one for doing diffs), that's not a problem anymore since it does it already.

The only true option here is to decide whether to output default unset values at all. I didn't make that choice because I wanted the output to reflect exactly the registry. But that's a matter of time if more readers are willing to have this instead.