Check that the key is found in the registry. This refers to keys and not
    value/data pairs. To check value/data pairs, use ``value_exists``

    Args:

        hive (str): The hive to connect to

        key (str): The key to check

        use_32bit_registry (bool): Look in the 32bit portion of the registry

    Returns:
        bool: True if exists, otherwise False

    Usage:

        .. code-block:: python

            import salt.utils.win_reg as reg
            reg.key_exists(hive='HKLM', key='SOFTWARE\\Microsoft')

def key_exists(hive, key, use_32bit_registry=False):
    '''
    Check that the key is found in the registry. This refers to keys and not
    value/data pairs. To check value/data pairs, use ``value_exists``

    Args:

        hive (str): The hive to connect to

        key (str): The key to check

        use_32bit_registry (bool): Look in the 32bit portion of the registry

    Returns:
        bool: True if exists, otherwise False

    Usage:

        .. code-block:: python

            import salt.utils.win_reg as reg
            reg.key_exists(hive='HKLM', key='SOFTWARE\\Microsoft')
    '''
    local_hive = _to_unicode(hive)
    local_key = _to_unicode(key)

    registry = Registry()
    try:
        hkey = registry.hkeys[local_hive]
    except KeyError:
        raise CommandExecutionError('Invalid Hive: {0}'.format(local_hive))
    access_mask = registry.registry_32[use_32bit_registry]

    handle = None
    try:
        handle = win32api.RegOpenKeyEx(hkey, local_key, 0, access_mask)
        return True
    except pywintypes.error as exc:
        if exc.winerror == 2:
            return False
        raise
    finally:
        if handle:
            win32api.RegCloseKey(handle)