Newbie Windows Registry Question

S

Stacy

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 :)
 
N

Nick Smallbone

Stacy said:
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
 
S

Stacy

Hi Nick,

Yes, I am having the same error message. I found some info on the
Microsoft page regarding error 1314 and Windows 2000...they made a
patch to fix it. I was unable to find anything relating to this
problem specifically for XP...hmmm. I wonder if it may have something
to do with my virus/firewall software....I'll keep looking. Thanks
for the help!

Stacy
 
D

Duncan Booth

(e-mail address removed) (Stacy) wrote in
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.
Any idea what I am doing wrong?

No, but if you simply want to get the job done, try this:

os.system(r'reg export HKLM\Software\Adobe c:\python23\samplekey.reg')
 
S

Stacy

Thanks Duncan!

That works perfectly! I told you I was a newbie :) Now I will be
able to finish up my little XP migration program and try it out next
week....

Thanks again,

Stacy
 
S

Stacy

Thanks Duncan!

That works perfectly! I told you I was a newbie :) Now I will be
able to finish up my little XP migration program and try it out next
week....

Thanks again,

Stacy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top