private static extern bool WTSQuerySessionInformationW( IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, out IntPtr ppBuffer, out int bytesReturned );
private static T QuerySessionInfo <T>(System.IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass) { IntPtr ppBuffer = IntPtr.Zero; uint pBytesReturned; if (WTSQuerySessionInformation(hServer, sessionId, wtsInfoClass, out ppBuffer, out pBytesReturned)) { try { T result; if (typeof(T).IsEnum) { Type underlyingType = Enum.GetUnderlyingType(typeof(T)); result = (T)Marshal.PtrToStructure(ppBuffer, underlyingType); } else { result = (T)Marshal.PtrToStructure(ppBuffer, typeof(T)); } return(result); } finally { WTSFreeMemory(ppBuffer); ppBuffer = IntPtr.Zero; } } return(default(T)); }
internal static extern bool WTSQuerySessionInformation( IntPtr hServer, int SessionId, WTS_INFO_CLASS WTSInfoClass, out IntPtr ppBuffer, out int pBytesReturned );
public static extern bool WTSQuerySessionInformation( IntPtr hServer, uint sessionId, WTS_INFO_CLASS wtsInfoClass, out IntPtr ppBuffer, out uint pBytesReturned );
private static extern int WTSQuerySessionInformation( IntPtr hServer, [MarshalAs(UnmanagedType.U4)] uint SessionId, [MarshalAs(UnmanagedType.U4)] WTS_INFO_CLASS WTSInfoClass, out IntPtr ppBuffer, [MarshalAs(UnmanagedType.U4)] out uint pBytesReturned );
internal static string GetUserSessionQueryInfo(int sessionId, WTS_INFO_CLASS info) { IntPtr buffer = IntPtr.Zero; uint bytesReturned; string queryInfo = null; if (sessionId < 0) { throw new ArgumentOutOfRangeException("sessionId"); } try { if (!WTSQuerySessionInformation(IntPtr.Zero, sessionId, info, out buffer, out bytesReturned)) { throw new Win32Exception(); } queryInfo = Marshal.PtrToStringAuto(buffer); } finally { if (buffer != IntPtr.Zero) { WTSFreeMemory(buffer); buffer = IntPtr.Zero; } } return(queryInfo); }
public static string QuerySessionInformation(int SessionId, WTS_INFO_CLASS info, IntPtr hServer) { IntPtr AnswerBytes; IntPtr AnswerCount; WTSQuerySessionInformationW(hServer, SessionId, (int)info, out AnswerBytes, out AnswerCount); return(Marshal.PtrToStringUni(AnswerBytes)); }
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 string GetString(IntPtr ptrOpenedServer, int active_session, WTS_INFO_CLASS whichOne) { var str = IntPtr.Zero; var returned = 0; if (WTSQuerySessionInformation(ptrOpenedServer, active_session, whichOne, ref str, ref returned)) { return(Marshal.PtrToStringAuto(str)); } return(""); }
static string GetSessionString(int sessionId, WTS_INFO_CLASS info) { if (!WTSQuerySessionInformation(IntPtr.Zero, sessionId, info, out IntPtr bytes, out uint byteCount)) { return(""); } var infoString = Marshal.PtrToStringAnsi(bytes); WTSFreeMemory(bytes); return(infoString); }
private static string GetWTSInformation(WTS_INFO_CLASS whatInfoNeeded) { IntPtr buffer = IntPtr.Zero; Int32 bytesReturned; string strClientName = ""; try { WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero; bool sucess = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, whatInfoNeeded, out buffer, out bytesReturned); if (sucess) { if (whatInfoNeeded == WTS_INFO_CLASS.WTSClientAddress) { WTS_CLIENT_ADDRESS oClientAddres = new WTS_CLIENT_ADDRESS(); try { oClientAddres = (WTS_CLIENT_ADDRESS)System.Runtime.InteropServices.Marshal.PtrToStructure(buffer, oClientAddres.GetType()); } catch { } strClientName = oClientAddres.bAddress[2] + "." + oClientAddres.bAddress[3] + "." + oClientAddres.bAddress[4] + "." + oClientAddres.bAddress[5]; } else { strClientName = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(buffer); } } } catch { } finally { if (buffer != IntPtr.Zero) { try { WTSFreeMemory(buffer); } catch { } buffer = IntPtr.Zero; } } return(strClientName); }
public static String getTerminalInfoString(WTS_INFO_CLASS wtsInfoClass) { IntPtr pBuf = IntPtr.Zero; uint pBytesReturned; WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, wtsInfoClass, out pBuf, out pBytesReturned); String result = Marshal.PtrToStringAnsi(pBuf); WTSFreeMemory(pBuf); return(result); }
public static byte[] getTerminalInfo(WTS_INFO_CLASS wtsInfoClass) { IntPtr pBuf = IntPtr.Zero; uint pBytesReturned; WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, wtsInfoClass, out pBuf, out pBytesReturned); byte[] buf = new byte[pBytesReturned]; Marshal.Copy(pBuf, buf, 0, (int)pBytesReturned); WTSFreeMemory(pBuf); return(buf); }
private static string QuerySessionInfo(System.IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass) { IntPtr ppBuffer = IntPtr.Zero; uint pBytesReturned; if (WTSQuerySessionInformation(hServer, sessionId, wtsInfoClass, out ppBuffer, out pBytesReturned)) { try { return(Marshal.PtrToStringAnsi(ppBuffer)); } finally { WTSFreeMemory(ppBuffer); ppBuffer = IntPtr.Zero; } } return(String.Empty); }
private static string QuerySessionInfo(IntPtr server, int sessionId, WTS_INFO_CLASS infoClass) { IntPtr buffer = IntPtr.Zero; try { uint bytesReturned; WTSQuerySessionInformation(server, sessionId, infoClass, out buffer, out bytesReturned); return Marshal.PtrToStringAnsi(buffer); } catch (Exception exc) { Log.Info("", exc); return String.Empty; } finally { WTSFreeMemory(buffer); buffer = IntPtr.Zero; } }
private static string QuerySessionInfo(IntPtr server, int sessionId, WTS_INFO_CLASS infoClass) { IntPtr buffer = IntPtr.Zero; try { uint bytesReturned; WTSQuerySessionInformation(server, sessionId, infoClass, out buffer, out bytesReturned); return(Marshal.PtrToStringAnsi(buffer)); } catch (Exception exc) { Log.Info("", exc); return(String.Empty); } finally { WTSFreeMemory(buffer); buffer = IntPtr.Zero; } }
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(); }
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(); } }
public static extern bool WTSQuerySessionInformation(IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, out IntPtr buffer, out int bytesReturned);
public static short QuerySessionInformationForShort(int sessionId, WTS_INFO_CLASS infoClass) { return(QuerySessionInformation(sessionId, infoClass, (mem, returned) => Marshal.ReadInt16(mem))); }
public static extern Boolean WTSQuerySessionInformation(IntPtr serverHandle, Int32 sessionId, WTS_INFO_CLASS wtsInfoClass, out IntPtr ppBuffer, out UInt32 pBytesReturned);
public static extern bool WTSQuerySessionInformation( IntPtr pServer, int iSessionID, WTS_INFO_CLASS oInfoClass, out IntPtr pBuffer, out uint iBytesReturned);
private static extern bool WTSQuerySessionInformation2(System.IntPtr hServer, int SessionId, WTS_INFO_CLASS WTSInfoClass, ref IntPtr ppBuffer, ref Int32 pCount);
public static string QuerySessionInformation(int SessionId, WTS_INFO_CLASS info) { return(QuerySessionInformation(SessionId, info, IntPtr.Zero)); }
public static extern bool WTSQuerySessionInformation(int ServerHandle, int SessionID, WTS_INFO_CLASS InfoClass, out WTS_CLIENT_DISPLAY[] Buffer, out int BytesReturned);
public static String getTerminalInfoString(WTS_INFO_CLASS wtsInfoClass) { IntPtr pBuf = IntPtr.Zero; uint pBytesReturned; WTSQuerySessionInformation (WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, wtsInfoClass, out pBuf, out pBytesReturned); String result = Marshal.PtrToStringAnsi (pBuf); WTSFreeMemory (pBuf); return result; }
public static T QuerySessionInformationForStruct <T>(ITerminalServerHandle server, int sessionId, WTS_INFO_CLASS infoClass) where T : struct { return(QuerySessionInformation( server, sessionId, infoClass, (buffer, returned) => (T)Marshal.PtrToStructure(buffer, typeof(T)))); }
public static string QuerySessionInformationForString(ITerminalServerHandle server, int sessionId, WTS_INFO_CLASS infoClass) { return(QuerySessionInformation( server, sessionId, infoClass, (buffer, returned) => buffer == IntPtr.Zero ? null : Marshal.PtrToStringAuto(buffer))); }
public static extern bool WTSQuerySessionInformation( System.IntPtr pServer, int iSessionID, WTS_INFO_CLASS oInfoClass, out System.IntPtr pBuffer, out uint iBytesReturned);
private static string GetString(IntPtr ptrOpenedServer, int active_session, WTS_INFO_CLASS whichOne) { IntPtr str = IntPtr.Zero; int returned = 0; if (WTSQuerySessionInformation(ptrOpenedServer, active_session, whichOne, ref str, ref returned)) { return Marshal.PtrToStringAuto(str); } return ""; }
public static extern bool WTSQuerySessionInformation(System.IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, ref System.IntPtr ppBuffer, ref int pBytesReturned);
private static extern bool WTSQuerySessionInformation(IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, ref IntPtr ppBuffer, ref int pBytesReturned);
internal static extern bool WTSQuerySessionInformation(IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, out StringBuilder ppBuffer, out int pBytesReturned);
private static extern bool WTSQuerySessionInformation2(IntPtr hServer, int SessionId, WTS_INFO_CLASS WTSInfoClass, ref IntPtr ppBuffer, ref Int32 pCount);
public static short QuerySessionInformationForShort(ITerminalServerHandle server, int sessionId, WTS_INFO_CLASS infoClass) { return(QuerySessionInformation(server, sessionId, infoClass, (buffer, returned) => Marshal.ReadInt16(buffer))); }
public static byte[] getTerminalInfo(WTS_INFO_CLASS wtsInfoClass) { IntPtr pBuf = IntPtr.Zero; uint pBytesReturned; WTSQuerySessionInformation (WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, wtsInfoClass, out pBuf, out pBytesReturned); byte[] buf = new byte[pBytesReturned]; Marshal.Copy (pBuf, buf, 0, (int)pBytesReturned); WTSFreeMemory (pBuf); return buf; }
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 extern bool WTSQuerySessionInformationW(IntPtr hServer, uint SessionId, WTS_INFO_CLASS WTSInfoClass, ref IntPtr ppBuffer, ref uint pBytesReturned);
public static extern bool WTSQuerySessionInformation(System.IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, out System.IntPtr ppBuffer, out uint pBytesReturned);
private static extern bool WTSQuerySessionInformation(IntPtr hServer, uint SessionId, WTS_INFO_CLASS WTSInfoClass, out IntPtr ppBuffer, out int pBytesReturned);