Friday
Apr172015

Free up RDP connections

The Terminal Server has exceeded the maximum number of allowed connections.

No doubt a result of someone closing their RDP window rather than logging off.

So I wrote a script that leveraged psexec.exe which killed the connections. You can tweak yours to your own needs, but I wanted something that would simply log off disconnected sessions rather than potentially intefering with someone's (active) work.

The contents of the .bat files follow. You'll want to run logoff.bat and feed two parameters: the DOMAIN\USERNAME of credentials that have local administrator rights on the targeted box and, of course, the name of the box you're trying to RDP into.

Prerequisites would be downloading psexec.exe and making sure you specify the path in logoff.bat. You'll also want to ensure you specify the full path to logoff2.bat

Here's the logoff2.bat file which actually uses QUERY to find disconnected sessions and log them off to make room for you. You'd want to call logoff.bat directly and then the actual heavy lifting is done by logoff2.bat

Note of caution: sometimes accounts are logged in and disconnected because there are interactive processes. Or maybe one of your colleagues has a long process running that they didn't want to sit up and babysit. Regardless this should log off any squatters that are keeping you from administering your machines. Cheers!