original_docstring: 
      Remove a user from the minion
  
      :param name:
      The name of the user to delete
  
      :param purge:
      Boolean value indicating that the user profile should also be removed when
      the user account is deleted. If set to True the profile will be removed.
  
      :param force:
      Boolean value indicating that the user account should be deleted even if the
      user is logged in. True will log the user out and delete user.
  
      CLI Example:
  
      .. code-block:: bash
  
          salt '*' user.delete name
      
docstring: Remove a user from the minion
docstring_tokens: Remove a user from the minion
code: def delete(name,
             purge=False,
             force=False):
      '''
      Remove a user from the minion
  
      :param name:
      The name of the user to delete
  
      :param purge:
      Boolean value indicating that the user profile should also be removed when
      the user account is deleted. If set to True the profile will be removed.
  
      :param force:
      Boolean value indicating that the user account should be deleted even if the
      user is logged in. True will log the user out and delete user.
  
      CLI Example:
  
      .. code-block:: bash
  
          salt '*' user.delete name
      '''
      # Check if the user exists
      try:
          user_info = win32net.NetUserGetInfo(None, name, 4)
      except win32net.error as exc:
          (number, context, message) = exc
          log.error('User not found: {0}'.format(name))
          log.error('nbr: {0}'.format(number))
          log.error('ctx: {0}'.format(context))
          log.error('msg: {0}'.format(message))
          return False
  
      # Check if the user is logged in
      # Return a list of logged in users
      try:
          sess_list = win32ts.WTSEnumerateSessions()
      except win32ts.error as exc:
          (number, context, message) = exc
          log.error('No logged in users found')
          log.error('nbr: {0}'.format(number))
          log.error('ctx: {0}'.format(context))
          log.error('msg: {0}'.format(message))
  
      # Is the user one that is logged in
      logged_in = False
      session_id = None
      for sess in sess_list:
          if win32ts.WTSQuerySessionInformation(None, sess['SessionId'], win32ts.WTSUserName) == name:
              session_id = sess['SessionId']
              logged_in = True
  
      # If logged in and set to force, log the user out and continue
      # If logged in and not set to force, return false
      if logged_in:
          if force:
              try:
                  win32ts.WTSLogoffSession(win32ts.WTS_CURRENT_SERVER_HANDLE, session_id, True)
              except win32ts.error as exc:
                  (number, context, message) = exc
                  log.error('User not found: {0}'.format(name))
                  log.error('nbr: {0}'.format(number))
                  log.error('ctx: {0}'.format(context))
                  log.error('msg: {0}'.format(message))
                  return False
          else:
              log.error('User {0} is currently logged in.'.format(name))
              return False
  
      # Remove the User Profile directory
      if purge:
          try:
              sid = getUserSid(name)
              win32profile.DeleteProfile(sid)
          except pywintypes.error as exc:
              (number, context, message) = exc
              if number == 2:  # Profile Folder Not Found
                  pass
              else:
                  log.error('Failed to remove profile for {0}'.format(name))
                  log.error('nbr: {0}'.format(number))
                  log.error('ctx: {0}'.format(context))
                  log.error('msg: {0}'.format(message))
                  return False
  
      # And finally remove the user account
      try:
          win32net.NetUserDel(None, name)
      except win32net.error as exc:
          (number, context, message) = exc
          log.error('Failed to delete user {0}'.format(name))
          log.error('nbr: {0}'.format(number))
          log.error('ctx: {0}'.format(context))
          log.error('msg: {0}'.format(message))
          return False
  
      return True
code_tokens: def delete ( name , purge = False , force = False ) : try : user_info = win32net . NetUserGetInfo ( None , name , 4 ) except win32net . error as exc : ( number , context , message ) = exc log . error ( 'User not found: {0}' . format ( name ) ) log . error ( 'nbr: {0}' . format ( number ) ) log . error ( 'ctx: {0}' . format ( context ) ) log . error ( 'msg: {0}' . format ( message ) ) return False try : sess_list = win32ts . WTSEnumerateSessions ( ) except win32ts . error as exc : ( number , context , message ) = exc log . error ( 'No logged in users found' ) log . error ( 'nbr: {0}' . format ( number ) ) log . error ( 'ctx: {0}' . format ( context ) ) log . error ( 'msg: {0}' . format ( message ) ) logged_in = False session_id = None for sess in sess_list : if win32ts . WTSQuerySessionInformation ( None , sess [ 'SessionId' ] , win32ts . WTSUserName ) == name : session_id = sess [ 'SessionId' ] logged_in = True if logged_in : if force : try : win32ts . WTSLogoffSession ( win32ts . WTS_CURRENT_SERVER_HANDLE , session_id , True ) except win32ts . error as exc : ( number , context , message ) = exc log . error ( 'User not found: {0}' . format ( name ) ) log . error ( 'nbr: {0}' . format ( number ) ) log . error ( 'ctx: {0}' . format ( context ) ) log . error ( 'msg: {0}' . format ( message ) ) return False else : log . error ( 'User {0} is currently logged in.' . format ( name ) ) return False if purge : try : sid = getUserSid ( name ) win32profile . DeleteProfile ( sid ) except pywintypes . error as exc : ( number , context , message ) = exc if number == 2 : pass else : log . error ( 'Failed to remove profile for {0}' . format ( name ) ) log . error ( 'nbr: {0}' . format ( number ) ) log . error ( 'ctx: {0}' . format ( context ) ) log . error ( 'msg: {0}' . format ( message ) ) return False try : win32net . NetUserDel ( None , name ) except win32net . error as exc : ( number , context , message ) = exc log . error ( 'Failed to delete user {0}' . format ( name ) ) log . error ( 'nbr: {0}' . format ( number ) ) log . error ( 'ctx: {0}' . format ( context ) ) log . error ( 'msg: {0}' . format ( message ) ) return False return True
short_docstring: Remove a user from the minion
short_docstring_tokens: Remove a user from the minion
comment: '''
      Remove a user from the minion
  
      :param name:
      The name of the user to delete
  
      :param purge:
      Boolean value indicating that the user profile should also be removed when
      the user account is deleted. If set to True the profile will be removed.
  
      :param force:
      Boolean value indicating that the user account should be deleted even if the
      user is logged in. True will log the user out and delete user.
  
      CLI Example:
  
      .. code-block:: bash
  
          salt '*' user.delete name
      '''$SEP$# Check if the user exists$SEP$# Check if the user is logged in$SEP$# Return a list of logged in users$SEP$# Is the user one that is logged in$SEP$# If logged in and set to force, log the user out and continue$SEP$# If logged in and not set to force, return false$SEP$# Remove the User Profile directory$SEP$# Profile Folder Not Found$SEP$# And finally remove the user account