andrewlocatelliwoodcock

Thoughts on Software

Archive for the ‘Tools and commands’ Category

Forcibly disconnecting users from a remote desktop session

with 3 comments

Following on from my last post on how to find out who is connected to a remote desktop session on  particular machine, there are occasions when you’ll want to actually forcibly disconnect someone so that you can log on to the machine yourself.

Turns out that there’s a command for that …

There’s a two step process of first identifying who you want to disconnect and secondly of actually disconnecting them. So, how to identify the users connected to the remote session and also how long they’ve been idle:

quser /server:[server name]
eg: quser /server:myServer

This gives back a table of information: USERNAME, SESSIONNAME, ID, STATE, IDLE TIME and LOGON TIME. Once you’ve identified who (if anyone) you want to kick off, usually based on who’s been idle the longest, you will need to note down the ID and then use that in the logoff command to actually log the user off:

logoff [id] /server:[server name]
eg: logoff 2 /server:myServer

And that’s it!

Here’s a redacted screenshot of the process in action:

redacted logoff example

Written by andrewlocatelliwoodcock

November 28, 2012 at 21:15

Find out who’s logged on to a Remote Desktop Session

with 7 comments

It’s a problem I’ve hit multiple times: I need to remote into a server to do some work but there are only a few sessions available and they’re all in use. I could ask someone if they can log off for a while but as it’s possibly one of a number of people this requires a bulk email. What I really need is a way to identify exactly who is logged onto that server so I can ask them if they can log off for a while …

After a fair amount of googling, I tracked down the query session command for Windows which will do exactly this. Here’s an example:

query session /server:[SERVERNAME]

where [SERVERNAME] is the name of the server you are trying to remote onto. So if we were trying to connect to a server named MyServer, we’d enter:

query session /server:MyServer

Here’s redacted example of the command line query in action

Redacted example of the query session command in action

Redacted example of the query session command in action

There’s a lot more to this command than just the /server switch and the command is covered in detail in a good tech article form Micrsoft available here: http://technet.microsoft.com/en-us/library/bb490800.aspx

 

My next post covers how to forcibly disconnect users from a session when necessary.

Enjoy!

Written by andrewlocatelliwoodcock

September 13, 2012 at 21:41