[Tutor] re: help with _winreg

James sendme105@hotmail.com
Sat, 28 Jul 2001 01:48:31 -0700


I couldn't get the LoadKey function working.  So I tried a different
approach.  I wrote the following instead:

from _winreg import *

rKey = ConnectRegistry(None,HKEY_LOCAL_MACHINE)
aKey= OpenKey(rKey, r"Software\testkey")
newKey=CreateKey(rKey, r"Software\destination")

def copy_str_values(fromKey, toKey):
    for i in range(QueryInfoKey(fromKey)[1]):
        value = str(EnumValue(fromKey, i)[0])
        data = str(EnumValue(fromKey, i)[1])
        SetValueEx(toKey, value, 0, REG_SZ, data)

copy_str_values(aKey, newKey)
CloseKey(aKey)
CloseKey(newKey)
DeleteKey(rKey, r"Software\testkey")
CloseKey(rKey)

I used it to make my first useful script!  :)

Thanks for the help,

James.