Click here to Skip to main content
Click here to Skip to main content

Import/Export registry sections as XML

By , 21 Jan 2003
 
Exporting registry sections as Xml to simplify registry diffs
Exporting registry sections as XML to simplify registry diffs

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 :

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 '02 : code complete. Ability to export one or more registry sections
  • Nov 08 '02 : Ability to import registry sections as well.
  • Jan 22 '03 : Export routine made much faster (x5 approximately), based on User feedback

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.

A list of licenses authors might use can be found here

About the Author

Stephane Rodriguez.
France France
Member
Addicted to reverse engineering. At work, I am developing business intelligence software in a team of smart people (independent software vendor).
 
Need a fast Excel generation component? Try xlsgen.
 

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralUnicode Versionmembervipin_nvk21 Dec '08 - 3:24 
I am unable to resolve unicode errors, specially for DWORD while exporting...
Can any one help me in this..Any working version for the same in UNICODE
QuestionAny plans to update for XP/Vista?membervcor9 Aug '07 - 15:30 
The current project can't be built under Visual Studio 2005 (after conversion, there are several cryptic warnings and a fatal manifest problem) Any plans for an update?.
GeneralYes it works!memberdisplayAlias24 Dec '04 - 18:12 
On my win 98 machine it was ok and quick.
Thank you for writing to vc 6 and compatibility.
Drawback. Do open a browser window solicited, as
it may be a large file (root) and I usually
jump at all 'popups' no matter who (implied the
greatest in the world of all others).
 

QuestionOk.... how about Unicode support??membersysop@HAL9K.com11 Nov '04 - 7:21 
Confused | :confused: Seems like a small thing but the rest of my code is already Unicode so I have to convert xmlreader.cpp, xmlwrite.cpp to use Unicode if I want to use them in my project...
 

AnswerRe: Ok.... how about Unicode support??memberDieguito30 Dec '04 - 1:25 
Ok, you've got a topic there, but why don't you go ahead and share your usefull work with the rest of the world? Rose | [Rose]
AnswerRe: Ok.... how about Unicode support??membernagadravid3 Dec '08 - 17:52 
Hi, I have also having the same problem... I tried to convert to UNICODE.but getting memory errors..Any help on this Smile | :)
GeneralAnother use...!!!!memberpotterdl6 Aug '04 - 7:30 
This is the first Registry tool that I have found so far that allows me to view/export the contents of a registry file that is not in the active Windows directory. Every other registry tool has defaulted to the current version of system.dat
 
By using drag and drop I was able to open an old version of system.dat and access/review/retrieve registry entries from a previous intall.
 
Thanks!   Big Grin | :-D
 
David Potter

GeneralExport reg sections without MFCmembergonx28 Mar '03 - 0:08 
Hi i've been struggling this programming problem for quite a while.. Would you have a sample code of exporting a registry section to XML without the use of MFC?
 
Thanks
GeneralRe: Export reg sections without MFCmember.S.Rod.28 Mar '03 - 2:12 

Here is how to proceed :
- from the code in this article, take the following files : basetypes.h, xmlwriter.h, xmlwriter.cpp, registryxmllib.h, registryxmllib.cpp
- integrate those files in your own app
- at compile-time, the compiler will complain of missing CString and CFile class declarations : just grab the CString.h and CFile.h files from this code[^] : I provide implementation for those classes so that they mimic what the MFC classes do, but don't require MFC at all.
 
Good luck!
GeneralRe: Export reg sections without MFCmembergonx28 Mar '03 - 16:10 
Hi
Just one last question. I just want your opinion of what may be better:
1. Read the windows registry directly.
2. Export it to xml then parse it.
 
Thanks. Sorry for these kinds of questionsSmile | :)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 22 Jan 2003
Article Copyright 2002 by Stephane Rodriguez.
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid