Logoff Remote Desktop sessions via command line tools

Source: Internet
Author: User

This trick I learned from my one of Ex-college. In Windows servers, only the remote desktop sessions allowed with administrative access.  There is situations, you can ' t connect to the server via Remote Desktop because of both sessions already active. Seen this dialog box. ("Remote Desktop disconnected", "This computer can ' t connect to the remote computer")

Usually Windows Administrators, open "Terminal Services Manager" (in Administrative tools), connect to the problematic Ser  Ver and log off the unwanted sessions. There is easy ways if you love command line based tools.

Query the Remote Server for current Terminal Sessions

To query and list the sessions in the remote session, you could use QUser.exe or QWinsta

1. Quser

Quser command comes with all the latest Windows clients and servers. This would list the sessions of the remote server (or local machine).

Note:if you is using Windows XP, you need-to-add this location into your System path:c:windowssystem32dllcache. To does this, in command prompt, type the following.

SET PATH =%PATH%; C:windowssystem32dllcache;

Quser help Shows,

C:anand>quser/?
Display information about users logged the system.

QUERY USER [username | sessionname | sessionid] [/SERVER:SERVERNAME]

Username identifies the username.
SessionName identifies the session named SessionName.
SessionID identifies the session with ID SessionID.
/server:servername the SERVER to being queried (default is current).

e.g.,

C:>quser/server:mycitrixsvr
USERNAME sessionname ID State IDLE time LOGON time
JohnDoe ica-tcp#966 Active 7 7/31/2008 3:04 PM
Averagejoe ica-tcp#969 1 Active 9 7/31/2008
Familyman ica-tcp#984 5 Active 1:06 7/31/2008 4:33 PM
Normaldude ica-tcp#987 2 Active 4 7/31/2008 6:20 PM

2. QWinsta

QWinsta is little different and better. It has more features and options.  It comes with all flavors of Windows. QWinsta command line help displays as,

C:>qwinsta/?
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 the user username.
SessionID identifies the session with ID SessionID.
/server:servername the SERVER to being 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.

e.g.,

C:>qwinsta/server:citrixserver
SessionName USERNAME ID State TYPE DEVICE
0 Disc Rdpwd
Ica-tcp 65536 Listen Wdica
Rdp-tcp 65537 Listen rdpwd
Console Conn Wdcon
ica-tcp#966 JohnDoe Active Wdica
ica-tcp#969 Apple 1 Active wdica
ica-tcp#984 Averagejoe 5 Active Wdica
ica-tcp#987 Familyman 2 Active Wdica
ica-tcp#989 whoisme 3 Active Wdica

You is welcome to try the other options QWinsta provides.

Logoff the Remote Sessions

To Log off the terminal session of the remote server, you can use any one of the command line tools. One of LOGOFF and another one is Rwinsta. Before you log off of the remote session, you should know the ' session ID ' which you get it from "Quser" OR "QWINSTA" command s as above stated.

1. Logoff

Logoff command kicks off (logging off) the specified remote session. Log off help shows,

C:>logoff/?
Terminates a session.

LOGOFF [sessionname | sessionid] [/server:servername] [/v]

SessionName the name of the session.
SessionID the session.
/SERVER:SERVERNAME Specifies the Terminal SERVER containing the user
Session to log off (default was current).
/V Displays information about the actions performed.

e.g.,

C:>logoff/server:infra-apps 1/v
Logging off session ID 1

2. Rwinsta

Rwinsta has same parameters and does same thing as log off command. It simply means Reset WINdows STAtion. The help goes as,

C:>rwinsta/?
Reset the session Subsytem hardware and software to known initial values.

RESET SESSION {sessionname | sessionid} [/server:servername] [/v]

SessionName identifies the session with name SessionName.
SessionID identifies the session with ID SessionID.
/server:servername the SERVER containing the session (default is current).
/V Display additional information.

e.g.,

C:>rwinsta/server:mywinserver 1

Note:rwinsta command does not return anything.

Happy re-setting The remote sessions (Hey, stop cursing your co-workers who didn ' t log off their sessions).

Logoff Remote Desktop sessions via command line tools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.