Remotely Logging off Windows Users

This is one of those things I need to do from time to time, but don’t use it enough to remember it.

How to query for users on a machine

First, how can we query to find out what users have a session on a remote machine? Windows provides the qwinsta.exe command which we can use to query for the sessions that are running The format is as follows:

qwinsta /server:<serverName>

You can also use quser.exe:

quser /server:<serverName>

How to log a user off of a machine

Now that we know what users are on a machine, how can we force one to disconnect? Again, there is a handy little command called logoff.exe that we can use to force a user to log off of a machine based off of their session ID. The format is as follows:

logoff <sessionId> /server:<serverName>

Warning: If you remotely log off a user, their log session goes away which could mean that the unsaved data is lost, or if the user is in the middle of an activity, they may come down to your office to chew you out.

Remote reboot or shutdown.

Switches for “shutdown”

/? Displays the Help listing
/i Displays the graphical user interface (GUI); it must be the first option
/l Logs off the current user; it cannot be used with the /d or /m options
/s Shuts down the computer
/r Shuts down and restarts the computer
/g Shuts down and restarts the computer and then restarts any registered applications
/a Aborts system Shutdown
/p Turns off the local computer with no timeout or warning
/h Hibernates the local machine
/e Documents the reason for shutting down the computer
/m Specifies the target computer; it is used with \\computername
/t xxx Where xxx is the number of seconds before Shutdown
/c “comment” Where “comment” is the reason for the Shutdown or restart
/f Forces running applications to close without warning users
/d [p|u:]xx:yy Provides the reason for the Shutdown action: p = planned; u= unplanned; xx supplies the major reason code; yy = supplies the minor reason code


Shutdown /m \\computername /s /t 5


Shutdown /m \\computername /r /t 5

Be the first to comment

Leave a Reply

Your email address will not be published.