I have a server located in a data centre miles away from where I work. It currently runs Windows 2000 Server. Every now and then when I try to connect to the server I get the following message about the number of Remote Desktop connections being exceeded:
Subsequently I cannot logon to the server and the Remote Desktop Connection window closes. On one occasion I contacted the data centre where the server is hosted and they logged onto the console of the server and logged the unused RDP sessions off (other administrators were not logging off the server when working, only closing the Remote Desktop Connection window). I could then logon myself remotely. As a result I had a quick think about how I could do this remotely and I now use one of the PSTools (developed by Mark Russinovich of Sysinternals – now Microsoft) to execute a couple of command line tools on the server remotely to disconnect the unused session(s) myself.
To do this I use psexec.exe to execute programs on the remote server. You should note that psexec.exe uses ports 139 and 445 (Netbios and File Sharing ports) and that in order for this to work the target computer/server should have these ports accessible by your own client computer. However, I would not recommend under any circumstances that these ports be opened to the internet because of the misuse of others and or virus’s that may be in circulation. Fortunately for me I have a direct connection to the data centre where the server is located and whilst these ports appear open for me the server remains disguised from the internet via a firewall from everyone else.
Open up a command prompt and navigate to the PSTools directory where psexec.exe resides. Now we need to get the Session IDs for all of the logged on users by running an application called query.exe on the remote server itself using psexec.exe:
psexec.exe \\(servername or ip) -u (adminusername) -p (adminpassword) query.exe session
That should return a list of enumerated users logged onto the server and the Session ID that they have been assigned.
Now we know the Session ID of the session we wish to close we can use an application called logoff.exe on the remote server again by running it using psexec.exe:
psexec.exe \\(servername or ip) -u (adminusername) -p (adminpassword) logoff.exe (session ID)
When this command executes the session that corresponds to the Session ID you obtained by running query.exe is logged off, thus freeing up a connection for you to log onto the server with.
Other options for connecting include running the Remote Desktop Client (mstsc.exe) with the /console switch which has been changed to /admin in newer versions of the client. I have used this method and sometimes still encountered problems logging on. You can also use the Terminal Services Manager as it has the ability to remotely connect to other Terminal Servers. If you want to use this method you can copy tsadmin.exe from:
C:\WINDOWS\system32
on Windows Server 2003 and run it on a Windows XP workstation to connect to Terminal Servers remotely and administer sessions.