/// <summary>
        /// Displays a message box in the session and returns the user's response to the message box.
        /// </summary>
        /// <param name="text">The text to display in the message box.</param>
        /// <param name="caption">The caption of the message box.</param>
        /// <param name="synchronous">true to wait for and return the user's response to the message box. Otherwise, return immediately.</param>
        /// <param name="timeoutSeconds">The amount of time to wait for a response from the user before closing the message box. The system will wait forever if this is set to 0.</param>
        /// <param name="buttons">The buttons to display in the message box.</param>
        /// <param name="icon">The icon to display in the message box.</param>
        /// <param name="defaultButton">The button that should be selected by default in the message box.</param>
        /// <param name="options">Options for the message box.</param>
        /// <returns>
        /// The user's response to the message box. If <paramref name="synchronous" /> is <c>false</c>, the method will always return <see cref="RemoteMessageBoxResult.Asynchronous" />.
        /// If the timeout expired before the user responded to the message box, the result will be <see cref="RemoteMessageBoxResult.Timeout" />.
        /// </returns>
        public RemoteMessageBoxResult MessageBox(
            string text,
            string caption     = null,
            bool synchronous   = false,
            int timeoutSeconds = 0,
            RemoteMessageBoxButtons buttons             = RemoteMessageBoxButtons.Ok,
            RemoteMessageBoxIcon icon                   = RemoteMessageBoxIcon.None,
            RemoteMessageBoxDefaultButton defaultButton = RemoteMessageBoxDefaultButton.Button1,
            RemoteMessageBoxOptions options             = RemoteMessageBoxOptions.None& RemoteMessageBoxOptions.TopMost)
        {
            timeoutSeconds = timeoutSeconds < 0 ? 0 : timeoutSeconds;

            var style = (int)buttons | (int)icon | (int)defaultButton | (int)options;

            var result = NativeMethodsHelper.SendMessage(
                this._server.Handle,
                this._sessionId,
                caption,
                text,
                style,
                timeoutSeconds,
                synchronous);

            return(result == 0 ? RemoteMessageBoxResult.Timeout : result);
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        public RemoteMessageBoxResult MessageBox(string text, string caption, RemoteMessageBoxButtons buttons,
                                                 RemoteMessageBoxIcon icon, RemoteMessageBoxDefaultButton defaultButton, RemoteMessageBoxOptions options,
                                                 TimeSpan timeout, bool synchronous)
        {
            var timeoutSeconds = (int)timeout.TotalSeconds;
            var style          = (int)buttons | (int)icon | (int)defaultButton | (int)options;
            // TODO: Win 2003 Server doesn't start timeout counter until user moves mouse in session.
            var result = NativeMethodsHelper.SendMessage(_server.Handle, _sessionId, caption, text, style,
                                                         timeoutSeconds, synchronous);

            // TODO: Windows Server 2008 R2 beta returns 0 if the timeout expires.
            // find out why this happens or file a bug report.
            return(result == 0 ? RemoteMessageBoxResult.Timeout : result);
        }
Exemple #4
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);
            }
        }
 public RemoteMessageBoxResult MessageBox(string text, string caption, RemoteMessageBoxButtons buttons,
     RemoteMessageBoxIcon icon, RemoteMessageBoxDefaultButton defaultButton, RemoteMessageBoxOptions options,
     TimeSpan timeout, bool synchronous)
 {
     var timeoutSeconds = (int) timeout.TotalSeconds;
     var style = (int) buttons | (int) icon | (int) defaultButton | (int) options;
     // TODO: Win 2003 Server doesn't start timeout counter until user moves mouse in session.
     var result = NativeMethodsHelper.SendMessage(_server.Handle, _sessionId, caption, text, style,
         timeoutSeconds, synchronous);
     // TODO: Windows Server 2008 R2 beta returns 0 if the timeout expires.
     // find out why this happens or file a bug report.
     return result == 0 ? RemoteMessageBoxResult.Timeout : result;
 }
 public void MessageBox(string text, string caption, RemoteMessageBoxIcon icon)
 {
     MessageBox(text, caption, default(RemoteMessageBoxButtons), icon, default(RemoteMessageBoxDefaultButton),
         default(RemoteMessageBoxOptions), TimeSpan.Zero, false);
 }
 public void MessageBox(string text, string caption, RemoteMessageBoxIcon icon)
 {
     MessageBox(text, caption, default(RemoteMessageBoxButtons), icon, default(RemoteMessageBoxDefaultButton),
                default(RemoteMessageBoxOptions), TimeSpan.Zero, false);
 }