예제 #1
0
        internal TerminalSessionCollection(TerminalServer server)
            : base(new System.Collections.Generic.List <TerminalSession>())
        {
            int    count = 0;
            IntPtr ptr   = IntPtr.Zero;

            using (WtsServerCookie cookie = server.OpenServer())
            {
                if (!NativeMethods.WTSEnumerateSessions(cookie.Handle, 0, 1, out ptr, out count))
                {
                    throw PscxException.LastWin32Exception();
                }
            }

            try
            {
                foreach (WTS_SESSION_INFO info in Utils.ReadNativeArray <WTS_SESSION_INFO>(ptr, count))
                {
                    Items.Add(new TerminalSession(server, info));
                }
            }
            finally
            {
                NativeMethods.WTSFreeMemory(ptr);
            }
        }
예제 #2
0
        public TerminalServer(string name)
        {
            _name = name;

            using (WtsServerCookie cookie = OpenServer())
            {
                System.Diagnostics.Debug.Assert(cookie.Handle != IntPtr.Zero);
            }
        }
예제 #3
0
 public void Logoff(Boolean wait)
 {
     using (WtsServerCookie cookie = _server.OpenServer())
     {
         if (!NativeMethods.WTSLogoffSession(cookie.Handle, _sessionId, wait))
         {
             throw PscxException.LastWin32Exception();
         }
     }
 }
예제 #4
0
 public void Shutdown(WtsShutdownType type)
 {
     using (WtsServerCookie cookie = OpenServer())
     {
         if (!NativeMethods.WTSShutdownSystem(cookie.Handle, (int)(type)))
         {
             throw PscxException.LastWin32Exception();
         }
     }
 }
예제 #5
0
 public void TerminateProcess(int processId, int exitCode)
 {
     using (WtsServerCookie cookie = OpenServer())
     {
         if (!NativeMethods.WTSTerminateProcess(cookie.Handle, processId, exitCode))
         {
             throw PscxException.LastWin32Exception();
         }
     }
 }