def OpenRegistryKey(hiveKey, key):
    """ Opens a keyHandle for hiveKey and key, creating subkeys as necessary """
    keyHandle = None
    try:
        curKey = ""
        keyItems = key.split('\\')
        for subKey in keyItems:
            if curKey:
                curKey = curKey + "\\" + subKey
            else:
                curKey = subKey
            keyHandle = win32api.RegCreateKey(hiveKey, curKey)
    except Exception, e:
        keyHandle = None
        print "OpenRegistryKey failed:", hiveKey, key, e
    return keyHandle
 Opens a keyHandle for hiveKey and key, creating subkeys as necessary 
recipes/Python/528896_Simplest_Registry_IO/recipe-528896.py