logoff Command Tutorial

logoff command is used to log off from the current Windows session from the command line. logoff command can be used for command prompt, MS-DOS, or cmd.exe as all of them are the same. logoff command can be also used to logoff different users from the remote desktop sessions. logoff command is available for all modern operating systems like Windows XP, Windows 7, Windows 8, Windows 10, Windows Server 2003, Windows Server 2008, Windows Server 2012, Windows Server 2016, Windows Server 2019.

logoff Syntax

logoff command has very simple syntax like below.

logoff SESSION SERVER OPTION
  • SESSION is the session name or session ID we want to end.
  • SERVER is the server or system we want to end sessions. If we will end for the current system we can omit this option.
  • OPTION is an option like printing log.

logoff Options

The logoff command can accept the following options and parameters.

OPTIONDESCRIPTION
SESSIONSpecify the sessions name
SESSIONIDSpecify the session ID
/server:SERVERNAMESpecify the SERVERNAME. Optional
/vVerbose or detailed output.
/?Display help information.

Logoff Current Session

You can use the logoff command without any parameter in order to end or logoff from the current user session. You do not need to provide any parameters.

C:\> logoff

Send Message Before Logoff

When the logoff command is issued for a specific user or all users their currently running processes or changes will be killed or lost. So before running logoff for other users sending them a message will be useful. The msg command can be used to send messages about logoff.

> msg *

List Sessions

In order to use the logoff command to end another user session, the sessions should be listed properly with the session ID. The sessions can be listed by using the query session command from the command line.

C:\>query session
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 services                                    0  Disc
>console           ismail                    3  Active
  • SESSIONNAME is the session name
  • USERNAME is the user currently logged in the given session.
  • ID is the session ID.
  • STATE is the session current state like active or passive.
READ  How To Find Computer Name In Windows?

Logoff Different User Session

We can also logoff different user sessions than current user session. We will just provide the user sessions ID. The session ID can be listed with the query session command which is decribed previously. In the following example we will logoff or kill the session with the session ID 3.

C:\> logoff 3

Logoff Different User Session On Remote Server or System

logoff command can be also used to kill or end session on the remote systems or server. You should provide the server name with the /server option and the session name or session id like below.

C:\> logoff 3 /server:dc.windowstect.com

Or IP address of the server can be also provided to run logoff command.

C:\> logoff 3 /server:192.168.10.20

You can also provide the session name instead of the session id like below.

C:\> logoff console /server:dc.windowstect.com

Logoff RPD Session

We can also log off remote desktop or RDP session with the logoff command. First, we will list current sessions with the query session command like below.

C:\>query session
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 services                                    0  Disc
 console                                     1  Conn
>rdp-tcp#61        Administrator             2  Active
 rdp-tcp                                 65536  Listen

We can see that the RDP session is named rdp-tcp#61 with the ID 2. Also the username is Administrator .We can end this RDP session with the SESSION NAME or SESSION ID like below.

C:\> logoff 2

C:\> logoff rdp-tcp#61

Leave a Comment