WTSGetActiveConsoleSessionId (kernel32)
Last changed: s_verdiesen@hotmail.com-89.146.46.169

.
Summary
The WTSGetActiveConsoleSessionId function retrieves the Terminal Services session currently attached to the physical console. The physical console is the monitor, keyboard, and mouse.

C# Signature:

/// <summary>
/// The WTSGetActiveConsoleSessionId function retrieves the
/// Terminal Services session currently attached to the physical console.
/// The physical console is the monitor, keyboard, and mouse.
/// </summary>
/// <returns>An <see cref="int"/> equal to 0 indicates that the current session is attached to the physical console.</returns>
/// <remarks>It is not necessary that Terminal Services be running for this function to succeed.
/// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/termserv/termserv/wtsgetactiveconsolesessionid.asp</remarks>
[DllImport("kernel32.dll")]
static extern int WTSGetActiveConsoleSessionId();

VB .NET Signature:

TODO

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

See WTSQuerySessionInformation

Sample Code:

int currentSessionId = WTSGetActiveConsoleSessionId();

Alternative Managed API:

TODO

Documentation