WTSDisconnectSession function (wtsapi32.h)

Disconnects the logged-on user from the specified Remote Desktop Services session without closing the session. If the user subsequently logs on to the same Remote Desktop Session Host (RD Session Host) server, the user is reconnected to the same session.

Syntax

BOOL WTSDisconnectSession(
  [in] HANDLE hServer,
  [in] DWORD  SessionId,
  [in] BOOL   bWait
);

Parameters

[in] hServer

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

[in] SessionId

A Remote Desktop Services session identifier. To indicate the current session, specify WTS_CURRENT_SESSION. To retrieve the identifiers of all sessions on a specified RD Session Host server, use the WTSEnumerateSessions function.

To be able to disconnect another user's session, you need to have the Disconnect permission. For more information, see Remote Desktop Services Permissions. To modify permissions on a session, use the Remote Desktop Services Configuration administrative tool.

To disconnect sessions running on a virtual machine hosted on a RD Virtualization Host server, you must be a member of the Administrators group on the RD Virtualization Host server.

[in] bWait

Indicates whether the operation is synchronous. Specify TRUE to wait for the operation to complete, or FALSE to return immediately.

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.

Requirements

Requirement Value
Minimum supported client Windows Vista
Minimum supported server Windows Server 2008
Target Platform Windows
Header wtsapi32.h
Library Wtsapi32.lib
DLL Wtsapi32.dll
API set ext-ms-win-session-wtsapi32-l1-1-0 (introduced in Windows 8)

See also

WTSEnumerateSessions