Query provides four different modes that help you
discover information about Terminal Server. This utility falls more in
line with Microsoft's latest strategy for working with Terminal Server,
so you should use it whenever possible in new scripts and batch files.
The following sections tell you about the process, session, user, and
Terminal Server (TermServer) modes.
1. PROCESS
The PROCESS mode helps
you discover information about Terminal Server processes. Every
application creates a process when it runs, so this information focuses
on the applications that Terminal Server is running. The output
information includes the username, session name, session identifier
(ID), Process Identifier (PID), and image (application) name. This mode
uses the following syntax:
QUERY PROCESS [* | processid | username | sessionname | /ID:nn |
programname] [/SERVER:servername]
The following list describes each of the command line arguments.
*
Displays all of the visible processes.
processid
Displays process information for the specified PID.
username
Displays all
of the processes belonging to a particular user. You'll always find
processes belonging to your personal account, local account, network
service account, and local service account.
sessionname
Displays all of the processes running in a particular session. The two default sessions are console and services.
/ID:
nn
Displays all
of the processes running within a particular session. You'll always see
two sessions. Session 0 works with the services sessions and session 1
works with the console sessions.
programname
Displays
all of the sessions associated with a particular program name. If
multiple people are using the same application, you'll see one session
for each user.
/SERVER:
servername
Enumerates
the specified processes on a particular Terminal Server. If you don't
have rights to access the Terminal Server, you'll see a security error
message. If the server isn't running Vista, Windows Server 2008 Full
version, or Server Core, you'll likely see an "Error Enumerating
Processes" message.
2. SESSION
The SESSION mode tells
you about the sessions running on Terminal Server. Depending on what
command line options you use, you can obtain a wealth of session
information. The default settings provide the session name, username,
session identifier, session state, connection type, and connection
device. This mode uses the following syntax:
QUERY SESSION [sessionname | username | sessionid] [/SERVER:servername]
[/MODE] [/FLOW] [/CONNECT] [/COUNTER]
The following list describes each of the command line arguments.
sessionname
Displays all of the processes running in a particular session. The two default sessions are console and services.
username
Displays all of the processes belonging to a particular user. You'll
always find processes belonging to your personal account, local account,
network service account, and local service account.
sessionid
Displays
all of the processes running within a particular session. You'll always
see two sessions. Session 0 works with the services sessions and session
1 works with the console sessions.
/SERVER:
servername
Enumerates the
specified processes on a particular Terminal Server. If you don't have
rights to access the Terminal Server, you'll see a security error
message. If the server isn't running Vista, Windows Server 2008 Full
version, or Server Core, you'll likely see an "Error Enumerating
Processes" message.
/MODE
Displays the
current line settings. The output changes to include several new columns
including the session name, state, device, type, baud, parity, data
bits, and stop bits.
/FLOW
Displays the
current flow control settings. The output changes to include several new
columns including the session name, state, device, type, and flow
control.
/CONNECT
Displays the
current connection mode. The output changes to include several new
columns including the session name, state, device, type, and connection
type.
/COUNTER
Displays
three counter settings that include total sessions created, total
sessions disconnected, and total sessions reconnected.
3. USER
The USER mode displays
information about users logged into Terminal Server. The output
information includes the username, session name, session identifier,
session state, idle time, and logon time. This mode uses the following
syntax:
QUERY USER [username | sessionname | sessionid] [/SERVER:servername]
The following list describes each of the command line arguments.
username
Displays all
of the processes belonging to a particular user. You'll always find
processes belonging to your personal account, local account, network
service account, and local service account.
sessionname
Displays all of the processes running in a particular session. The two default sessions are console and services.
sessionid
Displays
all of the processes running within a particular session. You'll always
see two sessions. Session 0 works with the services sessions and session
1 works with the console sessions.
/SERVER:
servername
Enumerates the
specified processes on a particular Terminal Server. If you don't have
rights to access the Terminal Server, you'll see a security error
message. If the server isn't running Vista, Windows Server 2008 Full
version, or Server Core, you'll likely see an "Error Enumerating
Processes" message.
4. TERMSERVER
The TERMSERVER
mode outputs information about Terminal Server. The information you
receive depends on the Terminal Server you query and the command line
options you select. This mode uses the following syntax:
QUERY TERMSERVER [servername] [/DOMAIN:domain] [/ADDRESS] [/CONTINUE]
The following list describes each of the command line arguments.
servername
Specifies the
name of the Terminal Server. The system must be running Terminal Server.
The Query utility won't return any information, even if you have
Terminal Server installed, unless Terminal Server is running at the time
of the query.
/DOMAIN:
domain
Specifies the domain to search for Terminal Servers. The Query utility assumes that you want to query the current domain.
/ADDRESS
Adds network and node address information to the output.
/CONTINUE
Displays all of
the Terminal Server information as continuous output, rather than
pausing after each screen. Use this option when you plan to redirect the
output to a file.