def setval(key, val, false_unsets=False, permanent=False):
    '''
    Set a single salt process environment variable. Returns True
    on success.

    key
        The environment key to set. Must be a string.

    val
        The value to set. Must be a string or False. Refer to the
        'false_unsets' parameter for behavior when set to False.

    false_unsets
        If val is False and false_unsets is True, then the key will be
        removed from the salt processes environment dict entirely.
        If val is False and false_unsets is not True, then the key's
        value will be set to an empty string.
        Default: False.

    permanent
        On Windows minions this will set the environment variable in the
        registry so that it is always added as an environment variable when
        applications open. If you want to set the variable to HKLM instead of
        HKCU just pass in "HKLM" for this parameter. On all other minion types
        this will be ignored. Note: This will only take affect on applications
        opened after this has been set.

    CLI Example:

    .. code-block:: bash

        salt '*' environ.setval foo bar
        salt '*' environ.setval baz val=False false_unsets=True
        salt '*' environ.setval baz bar permanent=True
        salt '*' environ.setval baz bar permanent=HKLM
    '''
    is_windows = salt.utils.platform.is_windows()
    if is_windows:
        permanent_hive = 'HKCU'
        permanent_key = 'Environment'
        if permanent == 'HKLM':
            permanent_hive = 'HKLM'
            permanent_key = r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'

    if not isinstance(key, six.string_types):
        log.debug('%s: \'key\' argument is not a string type: \'%s\'', __name__, key)
    if val is False:
        if false_unsets is True:
            try:
                os.environ.pop(key, None)
                if permanent and is_windows:
                    __utils__['reg.delete_value'](permanent_hive, permanent_key, key)
                return None
            except Exception as exc:
                log.error(
                    '%s: Exception occurred when unsetting '
                    'environ key \'%s\': \'%s\'', __name__, key, exc
                )
                return False
        else:
            val = ''
    if isinstance(val, six.string_types):
        try:
            os.environ[key] = val
            if permanent and is_windows:
                __utils__['reg.set_value'](permanent_hive, permanent_key, key, val)
            return os.environ[key]
        except Exception as exc:
            log.error(
                '%s: Exception occurred when setting'
                'environ key \'%s\': \'%s\'', __name__, key, exc
            )
            return False
    else:
        log.debug(
            '%s: \'val\' argument for key \'%s\' is not a string '
            'or False: \'%s\'', __name__, key, val
        )
        return False
Set a single salt process environment variable. Returns True
    on success.

    key
        The environment key to set. Must be a string.

    val
        The value to set. Must be a string or False. Refer to the
        'false_unsets' parameter for behavior when set to False.

    false_unsets
        If val is False and false_unsets is True, then the key will be
        removed from the salt processes environment dict entirely.
        If val is False and false_unsets is not True, then the key's
        value will be set to an empty string.
        Default: False.

    permanent
        On Windows minions this will set the environment variable in the
        registry so that it is always added as an environment variable when
        applications open. If you want to set the variable to HKLM instead of
        HKCU just pass in "HKLM" for this parameter. On all other minion types
        this will be ignored. Note: This will only take affect on applications
        opened after this has been set.

    CLI Example:

    .. code-block:: bash

        salt '*' environ.setval foo bar
        salt '*' environ.setval baz val=False false_unsets=True
        salt '*' environ.setval baz bar permanent=True
        salt '*' environ.setval baz bar permanent=HKLM