Example #1
0
        private static void AskQuestion(string[] args)
        {
            if (args.Length < 8)
            {
                Console.WriteLine(
                    "Usage: SessionInfo ask [server] [session id] [icon] [caption] [text] [timeout] [buttons]");
                return;
            }
            int seconds   = int.Parse(args[6]);
            int sessionId = int.Parse(args[2]);

            using (ITerminalServer server = GetServerFromName(args[1]))
            {
                server.Open();
                ITerminalServicesSession session = server.GetSession(sessionId);
                RemoteMessageBoxIcon     icon    =
                    (RemoteMessageBoxIcon)Enum.Parse(typeof(RemoteMessageBoxIcon), args[3], true);
                RemoteMessageBoxButtons buttons =
                    (RemoteMessageBoxButtons)Enum.Parse(typeof(RemoteMessageBoxButtons), args[7], true);
                RemoteMessageBoxResult result =
                    session.MessageBox(args[5], args[4], buttons, icon, default(RemoteMessageBoxDefaultButton),
                                       default(RemoteMessageBoxOptions), TimeSpan.FromSeconds(seconds), true);
                Console.WriteLine("Response: " + result);
            }
        }
Example #2
0
 public static void LogOffSession(ITerminalServer Server, int sessionID)
 {
     using (ITerminalServer server = Server)
     {
         server.Open();
         ITerminalServicesSession session = server.GetSession(sessionID);
         session.Logoff(false);
         server.Close();
         MessageBox.Show(new Form()
         {
             TopMost = true
         }, "Wysłano instrukcję wyłączenia sesji", "Rozłączanie sesji", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #3
0
        private static void GetSessionInfo(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Usage: SessionInfo get [server] [session id]");
                return;
            }
            int sessionId = int.Parse(args[2]);

            using (ITerminalServer server = GetServerFromName(args[1]))
            {
                server.Open();
                WriteSessionInfo(server.GetSession(sessionId));
            }
        }
Example #4
0
        private static void ListSessionProcesses(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Usage: SessionInfo listsessionprocesses [server] [session id]");
                return;
            }
            int sessionId = int.Parse(args[2]);

            using (ITerminalServer server = GetServerFromName(args[1]))
            {
                server.Open();
                ITerminalServicesSession session = server.GetSession(sessionId);
                WriteProcesses(session.GetProcesses());
            }
        }
Example #5
0
        private static void DisconnectSession(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Usage: SessionInfo disconnect [server] [session id]");
                return;
            }
            string serverName = args[1];
            int    sessionId  = int.Parse(args[2]);

            using (ITerminalServer server = GetServerFromName(serverName))
            {
                server.Open();
                ITerminalServicesSession session = server.GetSession(sessionId);
                session.Disconnect();
            }
        }
Example #6
0
        private static void SendMessage(string[] args)
        {
            if (args.Length < 6)
            {
                Console.WriteLine("Usage: SessionInfo message [server] [session id] [icon] [caption] [text]");
                return;
            }
            int sessionId = int.Parse(args[2]);

            using (ITerminalServer server = GetServerFromName(args[1]))
            {
                server.Open();
                ITerminalServicesSession session = server.GetSession(sessionId);
                RemoteMessageBoxIcon     icon    =
                    (RemoteMessageBoxIcon)Enum.Parse(typeof(RemoteMessageBoxIcon), args[3], true);
                session.MessageBox(args[5], args[4], icon);
            }
        }
Example #7
0
        public static void SendMessage(int sessionid, string message)
        {
            ITerminalServicesManager manager = new TerminalServicesManager();

            using (ITerminalServer server = manager.GetLocalServer())
            {
                server.Open();
                try
                {
                    var session = server.GetSession(sessionid);
                    session.MessageBox(message, "Сообщение");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка отправки сообщения: " + ex.Message);
                }
            }
        }
Example #8
0
        protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
            if (changeDescription.Reason == SessionChangeReason.SessionLogon)
            {
                try
                {
                    using (var token = _terminalServer.GetSession(changeDescription.SessionId).GetToken())
                    {
                        SHGetKnownFolderPath(_profile, 0, token.DangerousGetHandle(), out var pPath);
                        string filePath = Path.Combine(Marshal.PtrToStringAuto(pPath), ".earlystart");
                        Marshal.FreeCoTaskMem(pPath);
                        if (!File.Exists(filePath))
                        {
                            return;
                        }

                        using (var environment = new EnvironmentBlock(token))
                        {
                            foreach (string commandLine in File.ReadAllLines(filePath))
                            {
                                var startupInfo = new StartupInfo
                                {
                                    ByteCount = (uint)Marshal.SizeOf <StartupInfo>()
                                };

                                if (!CreateProcessAsUser(token.DangerousGetHandle(), null, commandLine, IntPtr.Zero, IntPtr.Zero, false, CreationFlags.UnicodeEnvironment, environment.Handle, Environment.SystemDirectory, ref startupInfo, out var processInfo))
                                {
                                    throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
                                }

                                CloseHandle(processInfo.ThreadHandle);
                                CloseHandle(processInfo.ProcessHandle);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _log.WriteEntry(e.ToString(), EventLogEntryType.Error);
                }
            }
        }
        private void refreshProcessTable()
        {
            this.tableProcess = new List <TableProces>();
            this.process      = AdminTools.getComputerProcess(this.computerName);
            ITerminalServer server = process[0].Server;

            foreach (ITerminalServicesProcess proc in process)
            {
                ITerminalServicesSession session = server.GetSession(proc.SessionId);
                if (showAllProcess | session.UserAccount != null)
                {
                    TableProces tmpProc = new TableProces(
                        proc.ProcessId,
                        proc.ProcessName,
                        session.UserName
                        );
                    tableProcess.Add(tmpProc);
                }
            }
            tableProcess.Sort((x, y) => x.processName.CompareTo(y.processName));
            //process_dataGridView.Refresh();
            process_dataGridView.DataSource = this.tableProcess;
        }
Example #10
0
 public ITerminalServicesSession this[int?sid] => sid != null?wtsServer.GetSession(sid.Value) : wtsServer.GetConsoleSession();
Example #11
0
 public ITerminalServicesSession FindSession(ITerminalServer server, int sessionID)
 {
     server.Open();
     return(server.GetSession(sessionID));
 }
Example #12
0
 public static ITerminalServicesSession GetConsoleSession(this ITerminalServer server)
 {
     return(server.GetSession((int)WTSGetActiveConsoleSessionId()));
 }