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.
[DllImport(@"wtsapi32.dll", SetLastError=true)]
static extern bool WTSEnumerateSessions(
IntPtr hServer,
int Reserved,
int Version,
out IntPtr SessionInfo,
ref int Count
);
public struct WTS_SESSION_INFO
{
public int SessionId;
public string pWinStationName;
public WTS_CONNECTSTATE_CLASS State;
}
public enum WTS_CONNECTSTATE_CLASS
{
/// <summary>
/// user is logged on to the WinStation.
/// </summary>
WTSActiveWTSActiveA,
/// <summary>
/// The WinStation is connected to the client.
/// </summary>
WTSConnectedWTSConnected,
/// <summary>
/// The WinStation is in the process of connecting to the client.
/// </summary>
WTSConnectQueryWTSConnectQuery,
/// <summary>
/// The WinStation is shadowing another WinStation.
/// </summary>
WTSShadowWTSShadow,
/// <summary>
/// The WinStation is active but the client is disconnected.
/// </summary>
WTSDisconnectedWTSDisconnected,
/// <summary>
/// The Win Station is waiting for a client to connect.
/// </summary>
WTSIdleWTSIdle,
/// <summary>
/// The WinStation is listening for a connection. A listener session waits for requests for new client connections.
/// No user is logged on a listener session. A listener session cannot be reset, shadowed, or changed to a regular client session.
/// </summary>
WTSListenWTSListen,
/// <summary>
/// The WinStation is being reset.
/// </summary>
WTSResetWTSReset,
/// <summary>
/// The WinStation is down due to an error.
/// </summary>
WTSDownWTSDown,
/// <summary>
/// The WinStation is initializing.
/// </summary>
WTSInitWTSInit
}
public WTS_SESSION_INFO[] GetSessions(string serveName)
{
WTS_SESSION_INFO[] sessionInfos;
int Count=0;
IntPtr hServer = new IntPtr(0);
hServer = WTSOpenServer(serveName);
if(hServer == IntPtr.Zero)
{
int ret = Marshal.GetLastWin32Error();
string msg = string.Format("\nError: [{0}] {1}\n", ret, GetErrorMessage(ret));
throw new ApplicationException(msg);
}
IntPtr ppSessionInfos = new IntPtr(0);
int sizeOfSessionInfo = Marshal.SizeOf(typeof(WTS_SESSION_INFO));
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).