This topic has not yet been rated - Rate this topic

WTSLogoffSession function

Applies to: desktop apps only

Logs off a specified Remote Desktop Services session.

Syntax

BOOL WTSLogoffSession(
  __in  HANDLE hServer,
  __in  DWORD SessionId,
  __in  BOOL bWait
);

Parameters

hServer [in]

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.

SessionId [in]

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

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

To log off 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.

bWait [in]

Indicates whether the operation is synchronous.

If bWait is TRUE, the function returns when the session is logged off.

If bWait is FALSE, the function returns immediately. To verify that the session has been logged off, specify the session identifier in a call to the WTSQuerySessionInformation function. WTSQuerySessionInformation returns zero if the session is logged off.

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

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Wtsapi32.h

Library

Wtsapi32.lib

DLL

Wtsapi32.dll

See also

WTSEnumerateSessions
WTSQuerySessionInformation

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Exception when bWait is true
On my Windows 7, 64 bit computer, WTSLogoffSession (with bWait set to true) fails with exception "Thread was interrupted from a wait state". In my case, the function is called from a secondary thread of a Windows service (running in session 0) and SessionId is the ID of the interactive user's session. I was expecting the function to simply return when the session was logged off, not throw an exception. Perhaps this behavior is not a bug (on my part or Microsoft's) but is just undocumented behavior.