public static ConnectionState GetConnectionState(ITerminalServerHandle server, int sessionId) { ProcessSessionCallback <ConnectionState> callback = delegate(IntPtr mem, int returned) { return((ConnectionState)Marshal.ReadInt32(mem)); }; return(QuerySessionInformation(server, sessionId, WTS_INFO_CLASS.WTSConnectState, callback)); }
public static T QuerySessionInformationForStruct <T>(ITerminalServerHandle server, int sessionId, WTS_INFO_CLASS infoClass) where T : struct { ProcessSessionCallback <T> callback = delegate(IntPtr mem, int returned) { return((T)Marshal.PtrToStructure(mem, typeof(T))); }; return(QuerySessionInformation(server, sessionId, infoClass, callback)); }
public static string QuerySessionInformationForString(ITerminalServerHandle server, int sessionId, WTS_INFO_CLASS infoClass) { ProcessSessionCallback <string> callback = delegate(IntPtr mem, int returned) { return(Marshal.PtrToStringAuto(mem)); }; return(QuerySessionInformation(server, sessionId, infoClass, callback)); }
private static T QuerySessionInformation <T>(ITerminalServerHandle server, int sessionId, WTS_INFO_CLASS infoClass, ProcessSessionCallback <T> callback) { int returned; IntPtr mem; if (NativeMethods.WTSQuerySessionInformation(server.Handle, sessionId, infoClass, out mem, out returned)) { try { return(callback(mem, returned)); } finally { NativeMethods.WTSFreeMemory(mem); } } else { throw new Win32Exception(); } }
private static T QuerySessionInformation <T>(ITerminalServerHandle server, int sessionId, WTS_INFO_CLASS infoClass, ProcessSessionCallback <T> callback) { int returned; IntPtr buffer = IntPtr.Zero; try { if (NativeMethods.WTSQuerySessionInformation(server.Handle, sessionId, infoClass, out buffer, out returned)) { return(callback(buffer, returned)); } else { throw new Win32Exception(); } } finally { if (buffer != IntPtr.Zero) { NativeMethods.WTSFreeMemory(buffer); buffer = IntPtr.Zero; } } }
public static int QuerySessionInformationForClientBuildNumber(ITerminalServerHandle server, int sessionId) { ProcessSessionCallback <int> callback = delegate(IntPtr mem, int returned) { return(Marshal.ReadInt32(mem)); }; return(QuerySessionInformation(server, sessionId, WTS_INFO_CLASS.WTSClientBuildNumber, callback)); }
private static T QuerySessionInformation <T>(int sessionId, WTS_INFO_CLASS infoClass, ProcessSessionCallback <T> callback) { int returned; IntPtr mem; if (WTSQuerySessionInformation(IntPtr.Zero, sessionId, infoClass, out mem, out returned)) { try { return(callback(mem, returned)); } finally { if (mem != IntPtr.Zero) { WTSFreeMemory(mem); } } } throw new Win32Exception(); }