Uninstall a specific KB.

    Args:

        path (str):
            The full path to the msu file to uninstall. This can also be just
            the name of the KB to uninstall

        restart (bool):
            ``True`` to force a restart if required by the installation. Adds
            the ``/forcerestart`` switch to the ``wusa.exe`` command. ``False``
            will add the ``/norestart`` switch instead. Default is ``False``

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    Raises:
        CommandExecutionError: If an error is encountered

    CLI Example:

    .. code-block:: bash

        salt '*' wusa.uninstall KB123456

        # or

        salt '*' wusa.uninstall C:/temp/KB123456.msu

def uninstall(path, restart=False):
    '''
    Uninstall a specific KB.

    Args:

        path (str):
            The full path to the msu file to uninstall. This can also be just
            the name of the KB to uninstall

        restart (bool):
            ``True`` to force a restart if required by the installation. Adds
            the ``/forcerestart`` switch to the ``wusa.exe`` command. ``False``
            will add the ``/norestart`` switch instead. Default is ``False``

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    Raises:
        CommandExecutionError: If an error is encountered

    CLI Example:

    .. code-block:: bash

        salt '*' wusa.uninstall KB123456

        # or

        salt '*' wusa.uninstall C:/temp/KB123456.msu
    '''
    # Build the command
    cmd = ['wusa.exe', '/uninstall', '/quiet']
    kb = os.path.splitext(os.path.basename(path))[0]
    if os.path.exists(path):
        cmd.append(path)
    else:
        cmd.append(
            '/kb:{0}'.format(kb[2:] if kb.lower().startswith('kb') else kb))
    if restart:
        cmd.append('/forcerestart')
    else:
        cmd.append('/norestart')

    # Run the command
    ret_code = __salt__['cmd.retcode'](cmd, ignore_retcode=True)

    # Check the ret_code
    # If you pass /quiet and specify /kb, you'll always get retcode 87 if there
    # is an error. Use the actual file to get a more descriptive error
    errors = {-2145116156: '{0} does not support uninstall'.format(kb),
              2359303: '{0} not installed'.format(kb),
              87: 'Unknown error. Try specifying an .msu file'}
    if ret_code in errors:
        raise CommandExecutionError(errors[ret_code])
    elif ret_code:
        raise CommandExecutionError('Unknown error: {0}'.format(ret_code))

    return True