Managing Terminal Services from the Command Line

In addition to the tools in Terminal Services Manager, there are quite a few command-line tools for working with Terminal Services. These commands can be divided into two categories:

  • Gathering information

  • Controlling user sessions

Gathering Terminal Services Information

Several commands are available for gathering Terminal Services information from the command line including the following:

  • QUERY PROCESS [* | ProcessId | UserName | SessionName | /ID:SessionId | Program-Name] [/Server:ServerName]—Displays information about processes being run in Terminal Services sessions on the server

  • QUERY SESSION [SessionName | UserName | SessionId] [/Server:ServerName]—Displays information about Terminal Services sessions

  • QUERY TERMSERVER [ServerName] [/Domain:domain] [/Address]—Displays the available application terminal servers on the network. The /Address parameter adds network and node addresses to the output.

  • QUERY USER [UserName | SessionName | SessionId] [/Server:ServerName]—Display information about users logged on to the system

These commands accept many common parameters, including the following:

  • ProcessId—The ID of the process on the terminal server that you want to examine

  • ServerName—The name of the remote terminal server you want to work with

  • SessionId—The ID of the session on the terminal server that you want to examine

  • SessionName—The name of the session on the terminal server that you want to examine

  • UserName—The name of the user whose sessions or processes you want to examine

These commands are very helpful when you are looking for Terminal Services information and you do not have to use parameters to obtain information. If you type query process at the command line, you get a list of all processes being run in Terminal Services sessions on the local terminal server, for example:

USERNAME      SESSIONNAME      ID      PID     IMAGE
>wrstanek     console          0       3204    explorer.exe
>wrstanek     console          0       3372    mshta.exe
>wrstanek     console          0       3656    licmgr.exe

If you type query session at the command line, you get a list of all sessions on the local terminal server, for example:

SESSIONNAME        USERNAME          ID        STATE       TYPE    DEVICE
>console           wrstanek          0         Active      wdcon
 rdp-tcp                             65536      Listen     rdpwd

If you type query user at the command prompt, you get a list of all users who have sessions on the local server, for example:

USERNAME           SESSIONNAME       ID        STATE       IDLE TIME   LOGON TIME
>wrstanek          console           0         Active             .    9/16/2004 10:31 AM
tomc               rdp-tcp#4         1         Active             1    9/16/2004 5:05 PM

If you type query termserver at the command prompt, you get a list of all known terminal servers in the enterprise:

Known Terminal servers
----------------------
TSSVR02
TSSVR03
TSSVR04

Tip

QUERY is a server command in Windows Server 2003

The QUERY command is available in Windows Server 2003 but not from a desktop computer. If you are using Windows XP Professional as your desktop system, however, you can resolve this dilemma by copying the Query.exe command from a server to your desktop. Type where query.exe at the command line on the server to locate the command, and then copy the command to your desktop.

Managing User Sessions from the Command Line

When you want to manage user sessions from the command line, you can use these commands:

  • SHADOW [SessionName | SessionId] [/Server:ServerName] [/v]—Allows you to take remote control of a user's session

  • TSCON [SessionName | SessionId] [/Password:password] [/v]—Allows you to connect to a user's session if you know that user's password

  • TSDISCON [SessionName | SessionId] [/Server:ServerName] [/v]—Allows you to disconnect a user's session

  • RESET SESSION [SessionName | SessionId] [/Server:ServerName] [/v]—Allows you to reset a user's session

  • LOGOFF [SessionName | SessionId] [/Server:ServerName] [/v]—Allows you to log off a user's session

As you can see, all these commands accept similar parameters. These parameters include the following:

  • SessionName—The name of the session on the terminal server that you want to work with

  • SessionId—The ID of the session on the terminal server that you want to work with

  • ServerName—The name of the remote terminal server you want to work with

These commands also allow you to set verbose output using the /V parameter.

Using these commands is fairly straightforward. For example, if you want to disconnect a user session with the session ID 2 on the remote server TS06, you'd type the command tsdiscon 2 /server:ts06.

If you are logged on locally to the Terminal Server, it's even easier, as all you have to type is tsdiscon 2.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset