def rename(name, new_name):
    '''
    Change the username for a named user

    :param str name:
        user name to change

    :param str new_name:
        the new name for the current user

    :return:
        True if successful. False is unsuccessful.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' user.rename jsnuffy jshmoe
    '''
    # Load information for the current name
    current_info = info(name)
    if not current_info:
        raise CommandExecutionError('User \'{0}\' does not exist'.format(name))

    # Look for an existing user with the new name
    new_info = info(new_name)
    if new_info:
        raise CommandExecutionError(
            'User \'{0}\' already exists'.format(new_name)
        )

    # Rename the user account
    # Connect to WMI
    pythoncom.CoInitialize()
    c = wmi.WMI(find_classes=0)

    # Get the user object
    try:
        user = c.Win32_UserAccount(Name=name)[0]
    except __HOLE__:
        raise CommandExecutionError('User \'{0}\' does not exist'.format(name))

    # Rename the user
    result = user.Rename(new_name)[0]

    # Check the result (0 means success)
    if not result == 0:
        # Define Error Dict
        error_dict = {0: 'Success',
                      1: 'Instance not found',
                      2: 'Instance required',
                      3: 'Invalid parameter',
                      4: 'User not found',
                      5: 'Domain not found',
                      6: 'Operation is allowed only on the primary domain controller of the domain',
                      7: 'Operation is not allowed on the last administrative account',
                      8: 'Operation is not allowed on specified special groups: user, admin, local, or guest',
                      9: 'Other API error',
                      10: 'Internal error'}
        raise CommandExecutionError(
            'There was an error renaming \'{0}\' to \'{1}\'. Error: {2}'
            .format(name, new_name, error_dict[result])
        )

    return info(new_name).get('name') == new_name
dataset/ETHPy150Open saltstack/salt/salt/modules/win_useradd.py/rename