In operations team or production support team, your daily task may involve logging on to several servers to perform some analysis. Production servers allow only a certain number of users to log in at a time.

When you try login to a server where the no. of users already logged in reach the max limit, it doesn’t allow you to login. I have seen many people use 'tsadmin' console (start-> run -> tsadmin) to connect to the server and kill the unused user sessions.

There is also a command line option to view the users connected/disconnected to a particular server and kill the unused sessions – qwinsta/logoff do the command line magic.

Lets see the syntax and their usage:

Display information about Terminal Sessions.

QUERY SESSION [sessionname | username | sessionid]
[/SERVER:servername] [/MODE] [/FLOW] [/CONNECT] [/COUNTER]
sessionname Identifies the session named sessionname.
username Identifies the session with user username.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server to be queried (default is current).
/MODE Display current line settings.
/FLOW Display current flow control settings.
/CONNECT Display current connect settings.
/COUNTER Display current Terminal Services counters information.

Terminates a session.

LOGOFF [sessionname | sessionid] [/SERVER:servername] [/V]
sessionname The name of the session.
sessionid The ID of the session.
/SERVER:servername Specifies the Terminal server containing the user session to log off (default is current).
/V Displays information about the actions performed.

a. To check the user sessions for a remote server, the general query will be:
cmd> qwinsta /SERVER:<server_name>

See the result as below:

Here, 3 columns are important to analyze – UserName, IsD, State. UserName gives the name of the user that is connected or disconnected. In the IsD column, 0 refers to the console session, others are remote sessions. State gives the details on the connectivity status of the users. If it is Disc, you can log that user off using the logoff command.

b. Log off a particular user from a remote server
You can logoff/disconnect a user using its Session ID

cmd> logoff /SERVER:<server_name> <session_id>

These are general commands. You may read further and explore other switch options to write customized commands based on your needs.


  1. Anonymous // June 18, 2014 at 6:15 AM  

    Invalid parameter(s)

    This is what windows Server 2012r2 states back, so if you have a W2012 up an running, then this wont work.

  2. Anonymous // September 22, 2014 at 8:32 AM  

    you have to add session name or session ID or a username after log off switch. It should work