31

How do I log a disconnected user off remotely?

For example, I remotely connect to a computer (with Dameware, if that matters) and run a command that takes a significant amount of time to complete. In that time I move on to other things. When I come back, (the command has presumably completed successfully) another user has switched to their account, leaving my account status as "Disconnected". How can I remotely log off my account without having to take control of the computer, switch to my account, log off, and have the user log in again?

thePurpleMonkey
  • 647
  • 2
  • 6
  • 11

6 Answers6

58
  1. First, check the session number with qwinsta:

     QWINSTA /server:YOURCOMPUTERNAMEHERE
    

Write down the session ID.

  1. Then use the logoff command:

     LOGOFF YOURSESSIONIDHERE /server:YOURCOMPUTERNAMEHERE
    

See if that works.

[Edit] You can limit the query so it only shows the session id for the user that you want to log off.

In order to do that you the username name to the command, like: QWINSTA /server:YOURCOMPUTERNAMEHERE USER

Luiz Angelo
  • 1,407
  • 1
  • 12
  • 17
  • QWINSTA gives me `Error 5 getting sessionnames Error [5]:Access is denied.` even though I am a local admin on the machine. – thePurpleMonkey Sep 26 '13 at 21:37
  • @thePurpleMonkey If this is a domain computer, you need to be the domain admin. If this is a personal computer, you may need to have exact same username on both PC (and both admin) and run the command from Luiz. qwinsta will attempt to connect using the 'current' credentials which may not have access on the remote computer. – Darius Sep 27 '13 at 05:40
  • @Darius you don't actually need to be the domain admin. I'm not one in my network and I can qwinsta machines without a problem. But the info is valuable none the less. Is it a domain machine or not? – Luiz Angelo Sep 27 '13 at 11:56
  • @Darius @Luiz Both my computer and the target computer are on the domain. I am not a domain admin, but I _am_ a local admin nonetheless. I tried using the default credentials, and also specifying `domain\username`, neither of which worked. I can run qwinsta on my own machine, but if I try on any other computer, it fails. – thePurpleMonkey Sep 28 '13 at 06:06
  • Welkl, if it fails I guess it's something related to the firewall. Have you check if the remote server acceps RPC calls? – Luiz Angelo Sep 28 '13 at 13:39
  • @thePurpleMonkey You are the local admin for the current computer, and for the remote computer? Run CMD as admin? Also since you mentioned you have local admin on the PC, you have identical username/password on both the local and remote PC? (example: Darius on the mylocalpc and Darius on myremotepc, and both have identical password as well) - This will work (or at least it does work on my workplace) – Darius Sep 29 '13 at 07:16
  • All firewalls on both computers are disabled. @Darius I'm local admin on both computers. I can launch any program I want as admin. I have identical credentials on both machines. Yet, I cannot run qwinsta on any machine except my own. I don't know what's different about my setup than anybody else's. – thePurpleMonkey Sep 30 '13 at 16:18
  • 4
    @thePurpleMonkey I saw this in some other online forum, to suggest for you to do a "net use \\servername" before running qwinsta. That command will allow your PC and the server to establish trusted connection. If your current username is rejected, it will ask you for username to login to \\servername. Once that is established, you should be able to use qwinsta. Reference Forum Answer: http://www.tomshardware.com/forum/172235-46-using-qwinsta-drop-terminal-services-sessions (at the bottom of the page by Anonymous - December 4, 2009) – Darius Oct 01 '13 at 05:02
  • @Darius Good idea, but no luck. Still says access denied. – thePurpleMonkey Oct 04 '13 at 15:50
  • 3
    Thank you all, you've been extremely helpful. The way I ended up solving this is opening a command prompt on the remote machine with PsExec, and running QWINSTA and LOGOFF from there. Then it finally worked. – thePurpleMonkey Oct 04 '13 at 15:52
  • Will this commands send force parameter (-f)? – IGRACH Sep 22 '16 at 11:15
  • If you are receiving an error 5 when running QWINSTA, ensure that the remote PC has "AllowRemoteRPC" enabled, as explained in this article: https://stackoverflow.com/questions/22155943/qwinsta-error-5-access-is-denied – JSanchez Nov 10 '17 at 17:22
3

Remotely logoff a user by username in one command:

logoff /server:"servername" | qwinsta /server:"servername" "username"
techraf
  • 4,852
  • 11
  • 24
  • 40
user592832
  • 31
  • 1
1

If you have PSTOOLS installed, this is SUPER easy. If you do not have PSTOOLS installed, please do so. You may want to copy all of the .exes to your C:\Windows\system32 directory. (in all fairness, if you don't have PS tools and you're a systemadmin... you don't know what you are missing!)

Now, run CMD.exe as an administrator on the local PC, input your admin credentials if/when prompted. Now type "psexec \\hostname cmd.exe" This command will run CMD.exe as your account, remotely, as if you are actually at the machine. In the title bar of the command prompt, you will see the remote host name called out when you have successfully connected.

Now type "query session". this will now print out all the sessions that are available active/inactive, you'll want to note the Session ID #.

now type in "logoff #" where # = the session id you took note of previously.

You could do this with home based network PCs, but you'll have to have the same account on BOTH systems, and it could get a little tricky.

This will DEFINITELY work with domain PCs as I have tested it several times now.

1

I believe you can do this with logoff from the command line (assuming the machine you're remoting into is Windows). If I understand your question correctly, a user logs in while you're away from your remote session and logs in under a different account. You will be able to log off from their account via cmd.

root
  • 3,672
  • 7
  • 27
  • 45
1

For most versions of Windows: Log in to the system using an admin-enabled account. Bring up the task manager ("Windows Security" under the Start button if you RDP, "taskmgr.exe" from the command line, or any other way you prefer.) Go back to the "Users" tab. You'll see your own session & any other sessions. Select the other user's session and right-click, then choose Disconnect or Logoff (or, you can select the session and use the buttons at the bottom to do either of these.)

image of User tab in task manager

If it is a disconnected session, you can also select it, right-click, and use Connect -- this will switch you into that session instead of the one you're in. Then, of course, you can log out the session.

Chindraba
  • 1,963
  • 1
  • 11
  • 25
Debra
  • 4,268
  • 1
  • 17
  • 24
-2

Doublevisionpro will allow you to log out users remotely. Run Doublevisionpro, select the user you want to log out, and then select the View command.