def reg_query_value(self, dce, connection, keyName, valueName=None):
        """
        Query remote registry data for a given registry value
        """
        def subkey_values(subkey_handle):
            dwIndex = 0
            while True:
                try:
                    value_type, value_name, value_data = get_value(subkey_handle, dwIndex)
                    yield (value_type, value_name, value_data)
                    dwIndex += 1
                except DCERPCSessionError as e:
                    if e.error_code == ERROR_NO_MORE_ITEMS:
                        break
                    else:
                        self.context.log.error(f'HostChecker.reg_query_value()->sub_key_values(): Received error code {e.error_code}')
                        return

        def get_value(subkey_handle, dwIndex=0):
            ans = rrp.hBaseRegEnumValue(dce=dce, hKey=subkey_handle, dwIndex=dwIndex)
            value_type = ans['lpType']
            value_name = ans['lpValueNameOut']
            value_data = ans['lpData']

            # Do any conversion necessary depending on the registry value type
            if value_type in (
                REG_VALUE_TYPE_UNICODE_STRING,
                REG_VALUE_TYPE_UNICODE_STRING_WITH_ENV,
                REG_VALUE_TYPE_UNICODE_STRING_SEQUENCE):
                value_data = b''.join(value_data).decode('utf-16')
            else:
                value_data = b''.join(value_data)
                if value_type in (
                    REG_VALUE_TYPE_32BIT_LE,
                    REG_VALUE_TYPE_64BIT_LE):
                    value_data = int.from_bytes(value_data, 'little')
                elif value_type == REG_VALUE_TYPE_32BIT_BE:
                    value_data = int.from_bytes(value_data, 'big')

            return value_type, value_name[:-1], value_data

        try:
            root_key, subkey = keyName.split('\\', 1)
        except ValueError:
            self.context.log.error(f'HostChecker.reg_query_value(): Could not split keyname {keyName}')
            return

        ans = self._open_root_key(dce, connection, root_key)
        if ans is None:
            return ans

        root_key_handle = ans['phKey']
        try:
            ans = rrp.hBaseRegOpenKey(dce, root_key_handle, subkey)
        except DCERPCSessionError as e:
            if e.error_code == ERROR_FILE_NOT_FOUND:
                return e

        subkey_handle = ans['phkResult']

        if valueName is None:
            _,_, data = get_value(subkey_handle)
        else:
            found = False
            for _,name,data in subkey_values(subkey_handle):
                if name.upper() == valueName.upper():
                    found = True
                    break
            if not found:
                return DCERPCSessionError(error_code=ERROR_OBJECT_NOT_FOUND)
        return data

        Query remote registry data for a given registry value
        
cme/modules/wcc.py