# Wednesday, September 27, 2006

In continuing with my Remote Desktop tricks (Who did not close their Remote Desktop Connection) , I thought I'd share another nugget of information. TSDISCON.exe is a command line tool included in Windows since 2000. With this tool you can disconnect a session from a remote server (Especially usefull for those times that someone forgot to logout and you keep receiving the maximum number of connections reached error.

Description of the TSDISCON Command

The tsdiscon command uses the following syntax:

tsdiscon SessionID | SessionName [/server:ServerName] /v

The parameters that are used by the tsdiscon command are:
SessionID: Use this parameter to specify the ID of the session that you want to disconnect. To determine the ID of the session that you want to disconnect, use the query session command.
SessionName: Use this parameter to specify the name of the session that you want to disconnect. To determine the name of the session that you want to disconnect, use the query session command.
/server:ServerName: Use this parameter to specify the Terminal Services server that hosts the session that you want to disconnect. If you omit this parameter, the current Terminal Services server is specified.
/v: Use this parameter to display information about the actions that are being performed.
NOTE: You can disconnect your own sessions, but if you want to disconnect another user's session, you must have Full Control access permissions. You cannot disconnect the console session.

How to Disconnect a Terminal Services Session

This is an example of how to use the tsdiscon command to disconnect a session on the current Terminal Services server:
1. In a Terminal Services session, click Start, and then click Run.
2. Type cmd, and then click OK.
3. Determine the name or ID of the session that you want to disconnect. To do so, type query session, and then press ENTER. You see a list of information about the sessions on the current Terminal Services server. The list may be similar to:
SESSIONNAME   USERNAME        ID      STATE    TYPE    DEVICE
 console      administrator       0   active   wdcon   
 rdp-tcp                      65536   listen   rdpwd
>rdp-tcp#1    user1               1   active   rdpwd
 rdp-tcp#2    user1               2   active   rdpwd
 rdp-tcp#3    user2               3   active   rdpwd
 rdp-tcp#4    user3               4   disc     rdpwd  
 rdp-tcp#5    user1               5   disc     rdpwd
                                  6   idle
                                  7  idle
						
Note that in this example, the name of the current session is rdp-tcp#1, the session ID is 1, and it is owned by user1.

4. To disconnect the current session, type the following line at the command prompt, and then press ENTER:
tsdiscon
5. To disconnect session 2 by using the session ID, and to display information about the disconnect operation, type the following line at the command prompt, and then press ENTER:
tsdiscon 2 /v
You see the following line and session 2 is disconnected:
Disconnecting sessionID2 from sessionname rdp-tcp#2
6. To disconnect session 5 by using the session name, type the following line at the command prompt, and then press ENTER:
tsdiscon rdp-tcp#5