Newbie Windows Registry Question

Nick Smallbone nick at nick8325.freeserve.co.uk
Mon Jul 12 14:04:17 EDT 2004


"Stacy" <stacycollings at yahoo.com> wrote in message
news:c7c55926.0407120913.6292e61c at posting.google.com...
> Hi All,
>
> I'm trying to automate some migration tasks on XP and one of the steps
> involved is to export a reg key to install on a new machine.  After
> days of surfing the web and trying things, I give!Ineedsome newbie
> help.  What I want is to export the given key to my USB drive for
> later import to the new machine's registry.  The Python code I've
> written also copies User files, favorites, etc...Here's an example of
> what I have tried as far as the reg key goes:
>
> import _winreg
> _winreg.SaveKey(hkey_local_machine\software\adobe,
> r"C:\Python23\samplekey.reg")
>
> This gives the following error:
> SyntaxError: invalid token
>
> Okay, so then I tried this:
> _winreg.SaveKey(r"hkey_local_machine\software\adobe",
> r"c:\python23\samplekey.reg")
>
> And I get this error message:
> TypeError: The object is not a PyHKEY object
>
> Any idea what I am doing wrong?
>
> Thanks!
>
> Stacy :)

Hmm, the first parameter to SaveKey needs to be an HKEY object. You can get
one of these by calling _winreg.OpenKey. So for example:

import _winreg
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Adobe")
_winreg.SaveKey(key, "c:\\python23\\samplekey.reg")

However, when I do that, I get a WindowsError: A required privilege is not
held by the client. The documentation says that SeBackupPrivilege is needed
to call SaveKey. It happens when I run it as administrator as well though,
so I'm not sure what's happening there.

Nick





More information about the Python-list mailing list