I’ve needed this info many times, so I figured I should probably put this down in my blog. If you encounter the error: “The terminal server has exceeded the maximum number of allowed connections” and “The system can not log you on. The system has reached its licensed logon limit. Please try again later. Please try again or consult your system administrator.” while trying to RDP into a Windows Server, that probably means someone closed their connection without logging off first. To get around this, follow the two command prompts below if you have rights. The easiest way to get rights is to map a drive with the administrator permissions.
query session /server:servername
This will provide you a list of sessions. You should see sessions you can kill such as “rdp-tcp#1”.
reset session 2 /server:servername
This will kill the session associated with that ID which is found in the third column from your query command.