Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than wtsapi32, prefix the name with the module name and a period.
WTSEnumerateSessions (wtsapi32)
.
C# Signature:
[
DllImport( "wtsapi32.dll",
SetLastError = true,
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Auto,
ThrowOnUnmappableChar = true
)
]
static extern int WTSEnumerateSessions(
IntPtr hServer,
UInt32 Reserved, // must be 0
UInt32 Version, // must be 1
ref IntPtr ppSessionInfo,
ref UInt32 pCount
);
VB Signature:
<DllImport("wtsapi32.dll", _
bestfitmapping:=True, _
CallingConvention:=CallingConvention.StdCall, _
CharSet:=CharSet.Auto, _
EntryPoint:="WTSEnumerateSessions", _
setlasterror:=True, _
ThrowOnUnmappableChar:=True)> _
Private Shared Function WTSEnumerateSessions( _
ByVal hServer As IntPtr, _
<MarshalAs(UnmanagedType.U4)> _
ByVal Reserved As Int32, _
<MarshalAs(UnmanagedType.U4)> _
ByVal Vesrion As Int32, _
ByRef ppSessionInfo As IntPtr, _
<MarshalAs(UnmanagedType.U4)> _
ByRef pCount As Int32) As Int32
End Function
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure WTS_SESSION_INFO
Dim SessionID As Int32 'DWORD integer
Dim pWinStationName As String ' integer LPTSTR - Pointer to a null-terminated string containing the name of the WinStation for this session
Dim State As WTS_CONNECTSTATE_CLASS
End Structure
Notes:
To free the returned buffer pointed by ppSessionInfo, call the WTSFreeMemory function.
To be able to enumerate a session, you need to have the Query Information permission
Tips & Tricks:
Please add some!
Sample Code:
Please add some!
Alternative Managed API:
Do you know one? Please contribute it!
This Terminal Services API call lists all local and remote sessions for a given server, including their state (e.g. connected, disconnected) and type (local, RDP). It is the basis for the output of qwinsta.exe.
3/25/2015 12:50:12 PM - -62.209.223.226
The WTSFreeMemory function frees memory allocated by a Terminal Services function.
7/12/2011 7:01:29 AM - -87.178.3.148
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).