WTSQuerySessionInformation function

Retrieves session information for the specified session on the specified Remote Desktop Session Host (RD Session Host) server. It can be used to query session information on local and remote RD Session Host servers.

Syntax


BOOL WTSQuerySessionInformation(
  _In_   HANDLE hServer,
  _In_   DWORD SessionId,
  _In_   WTS_INFO_CLASS WTSInfoClass,
  _Out_  LPTSTR *ppBuffer,
  _Out_  DWORD *pBytesReturned
);

Parameters

hServer [in]

A handle to an RD Session Host server. Specify a handle opened by the WTSOpenServer function, or specify WTS_CURRENT_SERVER_HANDLE to indicate the RD Session Host server on which your application is running.

SessionId [in]

A Remote Desktop Services session identifier. To indicate the session in which the calling application is running (or the current session) specify WTS_CURRENT_SESSION. Only specify WTS_CURRENT_SESSION when obtaining session information on the local server. If WTS_CURRENT_SESSION is specified when querying session information on a remote server, the returned session information will be inconsistent. Do not use the returned data.

You can use the WTSEnumerateSessions function to retrieve the identifiers of all sessions on a specified RD Session Host server.

To query information for another user's session, you must have Query Information permission. For more information, see Remote Desktop Services Permissions. To modify permissions on a session, use the Remote Desktop Services Configuration administrative tool.

WTSInfoClass [in]

A value of the WTS_INFO_CLASS enumeration that indicates the type of session information to retrieve in a call to the WTSQuerySessionInformation function.

ppBuffer [out]

A pointer to a variable that receives a pointer to the requested information. The format and contents of the data depend on the information class specified in the WTSInfoClass parameter. To free the returned buffer, call the WTSFreeMemory function.

pBytesReturned [out]

A pointer to a variable that receives the size, in bytes, of the data returned in ppBuffer.

Return value

If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

To retrieve the session ID for the current session when Remote Desktop Services is running, call WTSQuerySessionInformation and specify WTS_CURRENT_SESSION for the SessionId parameter and WTSSessionId for the WTSInfoClass parameter. The session ID will be returned in the ppBuffer parameter. If Remote Desktop Services is not running, calls to WTSQuerySessionInformation fail. In this situation, you can retrieve the current session ID by calling the ProcessIdToSessionId function.

To determine whether your application is running on the physical console, you must specify WTS_CURRENT_SESSION for the SessionId parameter, and WTSClientProtocolType as the WTSInfoClass parameter. If ppBuffer is "0", the session is attached to the physical console.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

Wtsapi32.h

Library

Wtsapi32.lib

DLL

Wtsapi32.dll

Unicode and ANSI names

WTSQuerySessionInformationW (Unicode) and WTSQuerySessionInformationA (ANSI)

See also

WTS_INFO_CLASS
WTS_CLIENT_ADDRESS
WTS_CLIENT_DISPLAY
WTS_CONNECTSTATE_CLASS
WTS_SESSION_ADDRESS
WTSCONFIGINFO
WTSINFOEX

 

 

Show:
© 2014 Microsoft