winreg is obviously only for Windows, and does not read registry hive files (NTUSER.DAT, etc.), but rather accesses the registry directly.
What you are looking for is a library for parsing bush files, and it looks like this might work:
http://rwmj.wordpress.com/2010/11/28/use-hivex-from-python-to-read-and-write-windows-registry-hive-files/
The sample code seems promising:
# Use hivex to pull out a registry key. h = hivex.Hivex ("/tmp/ntuser.dat") key = h.root () key = h.node_get_child (key, "Software") key = h.node_get_child (key, "Microsoft") key = h.node_get_child (key, "Internet Explorer") key = h.node_get_child (key, "Main") val = h.node_get_value (key, "Start Page") start_page = h.value_value (val) #print start_page # The registry key is encoded as UTF-16LE, so reencode it. start_page = start_page[1].decode ('utf-16le').encode ('utf-8') print "User %s IE home page is %s" % (username, start_page)
The downside is that it is still not pure python, but rather a python wrapper for another cross-platform library.
Edit:
If you should have clean python code without binary dependencies, you can take a look at this project: http://code.google.com/p/creddump/
It seems to be pure python and it can read registry bushes in a cross-platform manner, but a special-purpose tool, not a library - this code will probably need adaptation.
Boaz yaniv
source share