Newbie Windows Registry Question

Discussion in 'Python' started by Stacy, Jul 12, 2004.

  1. Stacy

    Stacy Guest

    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 :)
     
    Stacy, Jul 12, 2004
    #1
    1. Advertising

  2. "Stacy" <> wrote in message
    news:...
    > 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
     
    Nick Smallbone, Jul 12, 2004
    #2
    1. Advertising

  3. Stacy

    Stacy Guest

    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

    "Nick Smallbone" <> wrote in message news:<40f2d2a3$0$7804$>...
    > "Stacy" <> wrote in message
    > news:...
    > > 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
     
    Stacy, Jul 13, 2004
    #3
  4. Stacy

    Duncan Booth Guest

    (Stacy) wrote in
    news::

    > 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.

    <snip>
    >
    > 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')
     
    Duncan Booth, Jul 13, 2004
    #4
  5. Stacy

    Stacy Guest

    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

    Duncan Booth <> wrote in message news:<Xns9525AEA1D44C7duncanrcpcouk@127.0.0.1>...
    > (Stacy) wrote in
    > news::
    >
    > > 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.

    > <snip>
    > >
    > > 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')
     
    Stacy, Jul 13, 2004
    #5
  6. Stacy

    Stacy Guest

    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

    Duncan Booth <> wrote in message news:<Xns9525AEA1D44C7duncanrcpcouk@127.0.0.1>...
    > (Stacy) wrote in
    > news::
    >
    > > 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.

    > <snip>
    > >
    > > 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')
     
    Stacy, Jul 13, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    0
    Views:
    478
  2. HK
    Replies:
    1
    Views:
    3,696
    Cowboy \(Gregory A. Beamer\)
    Apr 1, 2004
  3. Replies:
    0
    Views:
    774
  4. Leny
    Replies:
    3
    Views:
    16,977
    Daniel
    Feb 1, 2005
  5. Collin Miller
    Replies:
    10
    Views:
    656
    Roger Pack
    Jul 9, 2010
Loading...

Share This Page