Windows Server 2012 / 2012 R2 - RDS - Unblock your users session as administrator

Page 1 / 1

When your users use RemoteApp programs or desktops that you have made available through the RDS solution, it's possible that one program crashes on the server.
It's also possible that their session has a problem and that you are the only one who can solve this problem. Indeed, only the administrator has access to the physical server to manage the sessions and the use of its resources.

  1. Close processes or the session from the GUI
  2. Close processes or the session from the command line
    1. Close a process on a specific session
    2. Close a specific session

1. Close processes or the session from the GUI

By using the graphical interface of your server, you can help your users with the task manager.

As an administrator, by clicking on the "More details" option in the task manager, you will be able to manage open sessions on your session host server, as well as open processes in each session.
For example, as an administrator, you could close a RemoteApp program (in this case : Microsoft Excel) remotely.

Or completely close the session of the remote user by right clicking "Sign off" (or "Log off") on it.
Then, your user will be able to access the desktops and/or programs RemoteApp they can use.

From the server manager, you can also disconnect or log off a user.
To do this, go to "Remote Desktop Services -> Collections -> Name of the collection (optional).
Then, in the list of connections, locate the name of your user and right-click "Log off" on it.

Once the session is closed from the server, your user will receive the following error message :

Plain Text

Your Remote Desktop Services session has ended.
...
Your network administrator or another user might have ended your session.
...

2. Close processes or the session from the command line

For fans of the command line or those who have installed a server in Core mode, here is how to close the processes and sessions of your users.

2.1. Close a process on a specific session

To begin, you must retrieve the session ID that corresponds to the session of the desired user (in our case : InformatiUser).

Batch

query session

This command will display a list of Terminal Server sessions open on the current server.

Plain Text

 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE

 services                                    0  Disc
>console           Administrator             1  Active
 rdp-tcp#0         InformatiUser             2  Active
 rdp-tcp                                 65536  Listen

To close RemoteApp programs or other processes on one of these sessions, you will need to specify on which session you want to close the process.
If you don't specify this information as a parameter, the process will be closed on your session and not the user's one.

To list the processes launched on a specific session, you will have to use the "query process" command by specifying the ID of the desired session.

Batch

query process /ID:2

Which give :

Plain Text

 USERNAME              SESSIONNAME         ID    PID  IMAGE
 system                rdp-tcp#0            2   3500  csrss.exe
 system                rdp-tcp#0            2   2564  winlogon.exe
 dwm-2                 rdp-tcp#0            2    328  dwm.exe
 informatiuser         rdp-tcp#0            2   1220  taskhostex.exe
 informatiuser         rdp-tcp#0            2   2936  rdpclip.exe
 informatiuser         rdp-tcp#0            2   2732  rdpinit.exe
 informatiuser         rdp-tcp#0            2   2292  rdpshell.exe
 informatiuser         rdp-tcp#0            2   1192  excel.exe

Or by specifying the name of the user.

Batch

query process InformatiUser

In this case, you will see only those launched as [user name]. The system processes will not be displayed.

Plain Text

 USERNAME              SESSIONNAME         ID    PID  IMAGE
 informatiuser         rdp-tcp#0            2   1220  taskhostex.exe
 informatiuser         rdp-tcp#0            2   2936  rdpclip.exe
 informatiuser         rdp-tcp#0            2   2732  rdpinit.exe
 informatiuser         rdp-tcp#0            2   2292  rdpshell.exe
 informatiuser         rdp-tcp#0            2   1192  excel.exe

To close a process on the right user session, the quickest is to target the process with its ID (which is unique per process per session).
Important : the PID changes each time the process is closed and restarted.

In our case, we will close "Microsoft Excel" which corresponds to the "excel.exe" process whose ID is : 1192

Batch

taskkill /PID 1192 /F

Display again the list of processes launched on this session.

Batch

query process InformatiUser

As you can see, the process "excel.exe" has disappeared from the list.

Plain Text

 USERNAME              SESSIONNAME         ID    PID  IMAGE
 informatiuser                              2   1220  taskhostex.exe
 informatiuser                              2   2936  rdpclip.exe
 informatiuser                              2   2732  rdpinit.exe
 informatiuser                              2   2292  rdpshell.exe

We then relaunched our Microsoft Excel RemoteApp program from the client computer to show you another technique.
For those who would like to close a process with the name of the executable file on a specific session, here are 2 possibilities.

1st possibility :

  • use the "SESSION" filter to target a specific session. In our case, this is the session with ID : 2.
  • use the "im" (which means : image) parameter to target a process by its name. In our case : excel.exe.

Batch

taskkill /FI "SESSION eq 2" /im:excel.exe /F

Plain Text

SUCCESS: The process "EXCEL.EXE" with PID 2220 has been terminated.

2nd possibility :

  • use the "USERNAME" filter to target a specific session. In our case, this is the session opened by this user : InformatiUser.
  • use the "im" (which means : image) parameter to target a process by its name. In our case : excel.exe.

Batch

taskkill /FI "USERNAME eq InformatiUser" /im:excel.exe /F

Plain Text

SUCCESS: The process"EXCEL.EXE" with PID 1552 has been terminated.

2.2. Close a specific session

To begin, list the active sessions on your session host server.

Batch

query session

This command will allow you to know the open sessions on your server, as well as the ID of each session.

Plain Text

 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 
 services                                    0  Disc
>console           Administrator             1  Active
 rdp-tcp#0         InformatiUser             2  Active
 rdp-tcp                                 65536  Listen

To close a session using its ID, use this command :

Batch

logoff 2

If you want to use the name of the session (which has nothing to do with the name of your user), use the command like this.
The name of the session being what is indicated in the "SESSION" column of the result returned by the "query session" command mentioned above.

Batch

logoff rdp-tcp#0

After the session is closed, your user will receive an error message :

Plain Text

Your Remote Desktop Services session has ended.
You were logged off the remote computer.