Thursday, December 17, 2009

Managing Terminal Services Sessions Remotely (Window xp and 2003)

Windows XP and 2003 have two command-line tools which is called qwinsta and rwinsta that can query and reset a remote session.


For example, let's say that I can't gain access to a server using Terminal Services because both sessions are used up. I can use another server to check the status of the first one. As long as the user has administrative rights on the non-accessible machine I would run this:

qwinsta /server:testserver

Where testserver is the name of the non-accessible machine.

The above command will display the following below information:

> qwinsta /server:testserver

SESSIONNAME     USERNAME        ID            STATE         TYPE        DEVICE
console                                                   0              Conn             wdcon
rdp-tcp                                           65536              Listen            rdpwd
rdp-tcp#470              fzi                          1             Active            rdpwd
rdp-tcp#470              grg                        3              Active            rdpwd
Now I know that fzi and grg are the two that are logged in. To disconnect either user session I would type this:

rwinsta /server:testserver 1 or 3 (depending which user session you want to terminate)

Notice the 1 or 3 which is the session ID we found from using qwinsta command above.
 
Or you can try and logoff the session remotely using two Windows utilities, quser.exe and logoff.exe. With quser you can find out the session names of the logged on users and use that information in a subsequent call to logoff.exe to close the session.
 
> quser /server:testserver
 
USERNAME    SESSIONNAME          ID        STATE         IDLE TIME      LOGON TIME
pjp                    rdp-tcp#5                       2          Active                    2:31        12/11/2009 3:39
PM

>logoff rdp-tcp#5 /server:testserver

No comments:

Post a Comment