WTSEnumerateListeners (wtsapi32)
Last changed: -207.195.114.48

.
Summary
This function is meant to query the listeners on the workstation it is invoked from.

C# Signature:

/// <summary>
/// This function is to be called twice.  
/// First time is to get pCount (function returns false with WinErr 122).  
/// Second Time is to get pointer of array (function returns true if successful)
/// Unfortunately this function cannot be used on another machine, unlike [winsta.dll] -> WinStationQueryInformationW ... see Cassia source code for details
/// </summary>
/// <param name="hServer"> Remote Server Handle not supported.  Value must be IntPtr.Zero ( WTS_CURRENT_SERVER_HANDLE ) </param>
/// <param name="pReserved">Value must be IntPtr.Zero</param>
/// <param name="Reserved">Always set to 0</param>
/// <param name="pListeners">A pointer to an array, filled when pCount is greater than 0</param>
/// <param name="pCount">If pListeners is IntPtr.Zero and pCount is 0, calling function will populate pCount</param>
/// <returns></returns>
[DllImport("wtsapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern bool WTSEnumerateListeners([In] IntPtr hServer,
                                         [In] IntPtr pReserved,
                                         [In] uint Reserved,
                                         [Optional] ref IntPtr pListeners,
                                         [In,Out] ref uint pCount);

Alternative Managed API:

//GitHub > Cassia > Impl > NativeMethods.cs
[DllImport("winsta.dll", CharSet = CharSet.Unicode, EntryPoint = "WinStationQueryInformationW", SetLastError = true)]
public static extern int WinStationQueryInformationRemoteAddress(IntPtr hServer, int sessionId,
                                                                 WINSTATIONINFOCLASS information,
                                                                 ref WINSTATIONREMOTEADDRESS buffer,
                                                                 int bufferLength, out int returnedLength);

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Documentation