/// <summary>
        /// Gets the sessions on the terminal server.
        /// </summary>
        /// <returns>An array of sessions.</returns>
        public TerminalServerSession[] GetSessions()
        {
            IntPtr dataPtr;
            int    count;

            TerminalServerSession[] sessions;

            if (!Win32.WTSEnumerateSessions(this, 0, 1, out dataPtr, out count))
            {
                Win32.ThrowLastError();
            }

            using (var data = new WtsMemoryAlloc(dataPtr))
            {
                sessions = new TerminalServerSession[count];

                for (int i = 0; i < count; i++)
                {
                    var session = data.ReadStruct <WtsSessionInfo>(i);
                    sessions[i] = new TerminalServerSession(
                        this,
                        session.SessionID,
                        session.WinStationName,
                        session.State
                        );
                }

                return(sessions);
            }
        }
        /// <summary>
        /// Gets the processes running on the terminal server.
        /// </summary>
        /// <returns>An array of processes.</returns>
        public TerminalServerProcess[] GetProcesses()
        {
            IntPtr dataPtr;
            int    count;

            TerminalServerProcess[] processes;

            if (!Win32.WTSEnumerateProcesses(this, 0, 1, out dataPtr, out count))
            {
                Win32.ThrowLastError();
            }

            using (var data = new WtsMemoryAlloc(dataPtr))
            {
                processes = new TerminalServerProcess[count];

                for (int i = 0; i < count; i++)
                {
                    var process = data.ReadStruct <WtsProcessInfo>(i);
                    processes[i] = new TerminalServerProcess(
                        process.ProcessId,
                        process.SessionId,
                        Marshal.PtrToStringUni(process.ProcessName),
                        process.Sid != IntPtr.Zero ? new Sid(process.Sid, _systemName) : null
                        );
                }

                return(processes);
            }
        }
        /// <summary>
        /// Gets the sessions on the terminal server.
        /// </summary>
        /// <returns>An array of sessions.</returns>
        public TerminalServerSession[] GetSessions()
        {
            IntPtr dataPtr;
            int count;

            if (!Win32.WTSEnumerateSessions(this, 0, 1, out dataPtr, out count))
                Win32.Throw();

            using (WtsMemoryAlloc data = new WtsMemoryAlloc(dataPtr))
            {
                TerminalServerSession[] sessions = new TerminalServerSession[count];

                for (int i = 0; i < count; i++)
                {
                    WtsSessionInfo session = data.ReadStruct<WtsSessionInfo>(0, WtsSessionInfo.SizeOf, i);
                    
                    sessions[i] = new TerminalServerSession(
                        this,
                        session.SessionID,
                        session.WinStationName,
                        session.State
                        );
                }

                return sessions;
            }
        }
        /// <summary>
        /// Gets the processes running on the terminal server.
        /// </summary>
        /// <returns>An array of processes.</returns>
        public TerminalServerProcess[] GetProcesses()
        {
            IntPtr dataPtr;
            int count;
            TerminalServerProcess[] processes;

            if (!Win32.WTSEnumerateProcesses(this, 0, 1, out dataPtr, out count))
                Win32.Throw();

            using (WtsMemoryAlloc data = new WtsMemoryAlloc(dataPtr))
            {
                processes = new TerminalServerProcess[count];

                for (int i = 0; i < count; i++)
                {
                    var process = data.ReadStruct<WtsProcessInfo>(0, WtsProcessInfo.SizeOf, i);
                    processes[i] = new TerminalServerProcess(
                        process.ProcessId,
                        process.SessionId,
                        Marshal.PtrToStringUni(process.ProcessName),
                        process.Sid != IntPtr.Zero ? new Sid(process.Sid, _systemName) : null
                        );
                }

                return processes;
            }
        }