Thursday, January 5, 2012

How to kill Remote Sessions Remotely

You'll need a Windows console running as an appropriate user, this can be dealt with using a quick runas command:

runas /noprofile /user:domainname\userid cmd
pause

In the console you can then use qwinsta to query for a server's connections, for example:
C:\WINNT\system32>qwinsta /server:someServerHost0290
SESSIONNAME USERNAME ID STATE TYPE DEVICE
console 0 Conn wdcon
rdp-tcp 65536 Listen rdpwd
rdp-tcp#59 userid2 2 Active rdpwd
userid1 1 Active rdpwd

Guessing that Session 1 is up for a quick death you can then use the rwinsta command to kill the connection:
C:\WINNT\system32>rwinsta /server:someServerHost0290 1

Done.