Как завершить сеанс другого пользователя windows

Несколько раз встречался с ситуацией, когда один из пользователей Windows Server с ролью RDS (Remote Desktop Services) запустил приложение, которое утекло и заняло всю доступную RAM. Удаленно подключиться к такому хосту по RDP невозможно. Чтобы завершить утекший процесс, нужно выполнить удаленный логофф пользователя. Для этого можно использовать встроенную команду logoff.

Синтаксис команды logoff.exe:

logoff /server:<servername> <session ID> /v

Команда logoff принимает ID сессии пользователя, которую нужно завершить. Чтобы вывести список активных сеансов пользователей на удаленном компьютере, выполните команду:

quser /server:RemoteComputerName

USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
admin console 1 Active none 1/25/2023 1:23 PM

quser - список активных сессий на удаленном компьютере Windows или RDS

В данном случае на компьютере выполнен локальный вход (console) под пользователем admin. ID этой сессии равно 1.

Можно получить ID сессии определенного пользователя:

quser /server:RemoteComputerName sidorov

Совет. Если пользователь подключен через Remote Desktop, в поле SESSIONNAME будет указано rdp-tcp#X.

Вы можете удаленно завершить сеанс пользователя по его ID сессии. Выполните команду:

logoff 1 /SERVER:RemoteComputerName /v

Logging off session ID 1

При завершении сеанса пользователя, будут завершены все его запущенные процессы.

Проверьте, что на удаленном компьютере не осталось активных сессий:

quser /server:RemoteComputerName

No User exists for *

Можно использовать небольшой скрипт, чтобы завершить все сеансы пользователей на нескольких терминальных серверах:

@echo off
setlocal
set servers=MSKRDS1 MSKRDS2
for %%s in (%servers%) do (
qwinsta /server:%%s | for /f "tokens=3" %%i in ('findstr /I "%username%"') do logoff /server:%%s %%i /v
)

Также для удаленного завершения сессий пользователей можно использовать встроенную утилиту rwinsta:

rwinsta rdp-tcp#12 /server:MSKRDS2

или

rwinsta 22 /server:MSKRDS2

rwinsta - сбросить удаленную сессию пользователя



October 14, 2019 updated by

Leave a reply »

How do I sign out other user accounts without restarting the computer? When someone forgets to log out of a public or shared PC, their account still consumes RAM in the background. To free up the resources being used by other logged-in accounts, you can log them off using Task Manager, Command Prompt and PowerShell.

Method 1: Log Off Another User Using Task Manager

Press the Ctrl + Shift + Esc keyboard shortcut to launch Task Manager. Go to the Users tab, it will list all users that are currently signed in to your system. Right-click on the user you want to log off and select the Sign off option.

You will get a warning that says the user’s unsaved data might be lost. Click on Sign out user when you need to proceed.

Method 2: Log Off Another User Using Command Prompt

Open the Command Prompt with administrative rights, run the query session command to see all users currently logged into the computer. Take note of the session ID of the user you want to sign out.

Next, run the following command to log off your desired account by specifying the session ID.
logoff ID

This method doesn’t give you any alert or confirmation that the user you’re signing out will lose unsaved work.

Method 3: Log Off Another User Using PowerShell

Open Windows PowerShell with administrative rights, and type the following commands. Replace “Server01” with your computer’s name and substitute “pcunlocker” with the name of the account you want to log out.
$server = 'Server01'
$username = 'pcunlocker'
$sessionId = ((quser /server:$server | Where-Object { $_ -match $userName }) -split ' +')[2]
logoff $sessionId /server:$server

Once logged off, the user account is no longer listed in Task Manager. Signing a user out this way has the same risk of losing all unsaved data as the above method.

  • Previous Post: Fix: Windows 10 Keeps Going to Sleep After 2 Minutes
  • Next Post: 3 Methods to Check Your Motherboard Model in Windows 10

Skip to content

How to Log Off Another User in Windows 10

Although the concept of multiple users sharing one device or one PC is getting rarer by the day, there are still cases when you have to share PCs and switch users fast. Sometimes you need to end a session for another user signed in to your computer. Here are a number of methods you can use.

The situation can be different when you need to end a user session. For example, someone just forgot to sign out from his or her user account, and left running apps and opened docs, so the remain in your computer’s memory and consume its system resources. In this case, it could be useful to kick out the inactive session for the other user.

There are no third party tools required. This can be done using either Task Manager, Command Prompt or PowerShell.

  1. Open the Task Manager app.
  2. If it looks as follows, switch it to the full view using the «More details» link in the bottom right corner.
  3. Click on the Users tab.
  4. Right-click on a user account you want to log off.
  5. Select Sign off from the context menu.
    Windows 10 Logoff Another User

You are done.

Alternatively, there are a couple of console tools we can use for the same purpose. Let’s review them.

Log Off Another User from the Command Prompt

  1. Open an elevated command prompt.
  2. Type or copy-paste the following command:query session. This will list available user sessions.
  3. Note the ID column value for the user you want to sign off.
    Windows 10 Logoff Another User With Cmd

  4. Now, execute the command logoff <ID>. For example, logoff 1.

You are done.

Finally, you can use PowerShell, as follows.

Log Off Another User from with PowerShell

  1. Open PowerShell as Administrator.Tip: You can add «Open PowerShell As Administrator» context menu.
  2. Type or copy-paste the following command:$sessionID = ((quser /server:'you computer name' | Where-Object { $_ -match 'user name to sign off' }) -split ' +')[2]
  3. Now, execute the command logoff $sessionID.
    Windows 10 Logoff Another User PowerShell

The PowerShell method is great when you know the exact user name. You can save it as a script and sign out other users with one click when needed.

That’s it.

Related blog posts:

  • Find the Sign Out Log in Windows 10
  • All ways to sign out from Windows 10

Support us

Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:

If you like this article, please share it using the buttons below. It won’t take a lot from you, but it will help us grow. Thanks for your support!

Не редко один компьютер делят несколько пользователей и пока пользователь не завершит сеанс, Windows 11 будет выделять для учетной записи ресурсы процессора и оперативную память.

Чтобы завершить сеанс другого пользователя нам понадобится «Диспетчер задач». Запускаем его любым удобным способом (например, горячими клавишами «Ctrl+Shift+Esc»). В окне диспетчера задач переходим во вкладку «Пользователи», затем находим пользователя, сеанс которого необходимо завершить и щелкаем по нему правой кнопкой мыши. В появившемся контекстном меню нажимаем на «Выйти».

При этом появится предупреждение «Если вы выполнили выход для пользователя, несохраненные данные пользователя могут быть утеряны. Вы хотите продолжить?», для подтверждения выхода нажимаем на кнопку «Выход пользователя».

There are multiple ways to log off the current user on a Windows system using the command line.  The version of the commands below will depend on the Windows version, the interface you are using to log off the user (e.g. Remote Command Prompt, RMM, Local Command Prompt) etc..

The command to force the current user to log off  immediately using the command line in Windows is:

shutdown /l /f /t 00

Sometimes you will need to use a “-” instead of a “/”

shutdown -l -f -t 00

If you’d like to log off the session giving the current user the chance to save any work you would just exclude the “/f”

shutdown /l

or

shutdown -l

On some remote management systems you can’t issue the shutdown command.  In these cases what you need to do is find out the current user’s active session number by issuing the following command:

query user

Query User

You will then be able to see the current user’s Id and issue the logoff command instead:

logoff 1

Where 1 is the ID of the user you are logging off after performing the query user command.

The following command has been tested on Windows XP, Windows 7, Windows 8, Windows 8.1, Windows 10.  Your mileage may vary on other version of windows.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Драйвер для дисковода windows 7 64 bit
  • Повышенная производительность или оптимальная windows 10
  • Windows 7 ikev2 ошибка 809
  • Как отобразить формат файла в windows 11
  • Минимальная видеокарта для windows 10