PsExec – Remotely Connect and Logoff a User

So, as the title says, sometimes when you have two users already connected remotely to a server, you need to disconnect someone, or to log him off or something…

Well, you contact that person and ask politely to logoff by him\herself, and they don´t want to do it right, or they say that you should do it. But how, you ask yourself?

The answer is PSEXEC 🙂 it is really a cool app from Microsoft, which contain a bunch of exe files which you can use for some remote management.

So, in my case, I needed to remotely logoff a user so I can login remotely and perform few tasks.

First of all, it would be a nice idea to download PSEXEC: PsExec Download Page

Next, extract the content in C:\Windows\System32 – (make sure the content is directly extracted in this folder, otherwise you would need to provide a path every time when you want to execute some of the psexec tools).

Open CMD and type: psexec.exe \\server_name -u username -p password cmd

where:

server_name – is the actual server to which you try to access (can be IP address, NETBIOS name, or FQDN name)

username – is the user with admin rights which you will use to access the server remotely

password – is the pass of the user

cmd – is the name of the app you will use

Example: psexec.exe \\server01.contoso.com -u contoso\vladimir -p Pa$$w0rd cmd

First time you use psexec, you will have to accept the agreement.

Right after that, if you have entered a valid server name, username and password, you will connect to the remote machine.

Next, you type the following: query session

You should receive something like this:





As you can see, we have one user who is disconnected. And we want to log him\her off asap.

The ID we want to logoff is 2. So, in order to do that, we run this command:

logoff 2

and that is it. By using PsExec, you were able to logoff user remotely from a server:

Just type exit to exit the session, and you will be returned to CMD on a local machine.