[Tutor] Copying registry entries

Scott Widney SWidney@ci.las-vegas.nv.us
Fri Apr 25 14:03:21 2003

> I'd like to write a script to back up my Outlook
> Express (WinXP e-mail) data. Most of the information
> is in files and folders, which I understand how to
> copy. However, some of the information to back up is
> stored in registry keys. ... Can anyone help me
> understand how to copy a registry key?
> As always, thank you! -- Al C.

It's true, the documentation for the Win32 extensions is pretty sparse. And
if you're not familiar with the API, it's hard to know where to start
looking. But what you want is there, under Win32 API, Modules, win32api in
the Python for Win32 Extensions Help. There are 20-or-so functions there
specifically for dealing with the registry. Here's an example fresh off the

>>> import win32api
>>> import win32con
>>> key = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE,
        'SOFTWARE\\Python\\PythonCore\\2.2\\PythonPath', 0,
>>> val = win32api.RegQueryValueEx(key, '')
>>> val
('C:\\Python22\\Lib;C:\\Python22\\DLLs;C:\\Python22\\Lib\\lib-tk', 1)
>>> win32api.RegCloseKey(key)

There is more that you'll want to take advantage of, but this should give
you a good start.