Tuesday, January 5, 2016

Logoff remote desktop sessions remotly via command line

Below method works if you can establish the required rights on the remote server.
 
1) Check who is connected / look for a in-active session

 quser /server:<ServerName/IP>
*** This command is the same as the query user command.  
C:>quser /server:ServerABC
USERNAME           SESSIONNAME         ID   STATE   IDLE TIME  LOGON TIME
 Norm                                  12   Disc        none   03/02/2015 20:51
 Firman             ica-tcp#69          1   Active          .  03/03/2015 08:15

Or we can also use 

qwinsta /server:<ServerName/IP>
C:>qwinsta /server:ServerABC
 SESSIONNAME       USERNAME                 ID  STATE     TYPE        DEVICE
 ica-tcp                                   65536  Listen  wdica
 rdp-tcp                                   65537  Listen  rdpwd
 ica-tcp#69          Norm                   12    Disc    wdica
 console             Firman                 1     Active  wdcon

From the above results, I see that Norm has a disconnected session, which I can probably end. Or I can also kill Firman's active session.

2) Once I have session name or session ID, I can use "LogOff" command or "RWInsta"

C:>logoff /?
Terminates a session.

LOGOFF [sessionname | sessionid] [/SERVER:servername] [/V]
C:>RWinsta /?
Reset the session subsytem hardware and software to known initial values.

RESET SESSION {sessionname | sessionid} [/SERVER:servername] [/V] 

In the above case, I would like to kill Norm’s session, which is Disconnected. So I use below command.  12 is the session ID noted. 

logoff /server:ServerABC 12 /v
Logging off session ID 1

Or
 
RWinsta /Server:ServerABC 12

Thanks,
R.H


No comments: