Search This Blog

11 October, 2021

Remote logoff user

 

To log off the end user from a remote system you will need a few things. Just To start with you'll need to know what the user's session ID number is on that device to obtain this you'll use the Q user tool to query the system remotely.

If you were to just type quser in your command prompt it would return all the active computers on the current system you're logged into.

PS> quser


This is mostly helpful for server situations where you may have multiple users and log in and out of a device that you're on and you need to find out who else is logged in. 
The same goes for remote devices you'll use the flag /server: the name of the remote computer.
For the sake of brevity will use your local system as the server that will target this works for remote systems as well. (Please note that you must be in the administrative group in order to remotely run this query.)

PS> quser /server:RemoteComputerName





Now that we know what users are logged in to a remote server we can use another windows called log off along with the user session ID number and the flag server and the target computer name.
In the following example will use a test system setup where I where I am logged into an RDP session. 

PS> quser /server:'HAEA-ENG-TEST01'


Now that we know who's logged in and what their session ID number is we can go about using the log off command through remotely logged that particular user off. (as a side note this session also give you basic information as to how the user is logged in. In this case I'm using RDP to remotely connect to a test system.)
In this instance we are going to log off this session ID number 2 on the engineering test system one with the following command.

logoff 2 /server:'HAEA-ENG-TEST01'


There will be no output as two the status of logging out from the command line however if you rerun quser to query this system once again you'll see that the user session no longer exists on that system.
In In our example will find that there is no other users logged into that computer at this time including the targeted user you just logged out.