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); } }
/// <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; int style = (int)buttons | (int)icon | (int)defaultButton | (int)options; RemoteMessageBoxResult result = NativeMethodsHelper.SendMessage( this._server.Handle, this._sessionId, caption, text, style, timeoutSeconds, synchronous); return(result == 0 ? RemoteMessageBoxResult.Timeout : result); }
public static extern int WTSSendMessage( IntPtr hServer, int sessionId, [MarshalAs(UnmanagedType.LPTStr)] string title, int titleLength, [MarshalAs(UnmanagedType.LPTStr)] string message, int messageLength, int style, int timeout, out RemoteMessageBoxResult result, bool wait);
public RemoteMessageBoxResult MessageBox(string text, string caption, RemoteMessageBoxButtons buttons, RemoteMessageBoxIcon icon, RemoteMessageBoxDefaultButton defaultButton, RemoteMessageBoxOptions options, TimeSpan timeout, bool synchronous) { int timeoutSeconds = (int)timeout.TotalSeconds; int style = (int)buttons | (int)icon | (int)defaultButton | (int)options; // TODO: Win 2003 Server doesn't start timeout counter until user moves mouse in session. RemoteMessageBoxResult 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 ShowMessageBoxAndGetResponse([TestConfigurations] ServerConfiguration config) { using (var context = new ServerContext(config)) { using (var connection = context.OpenRdpConnection()) { var title = "Test " + Guid.NewGuid(); context.Source.StartShowingMessageBox(context.TargetConnection, connection.SessionId, title, "Hello!", RemoteMessageBoxButtons.AbortRetryIgnore, TimeSpan.Zero); Assert.That(context.Target.WindowWithTitleExists(connection.SessionId, title)); const RemoteMessageBoxResult expected = RemoteMessageBoxResult.Retry; // The automation ID of the button in the window is 4. context.Target.ClickButtonInWindow(connection.SessionId, title, ((int)expected).ToString()); Assert.That(context.Source.GetLatestMessageBoxResponse(), Is.EqualTo(expected)); } } }
private void SetLastMessageBoxResult(RemoteMessageBoxResult result) { _lastResult = result; }
public static extern int WTSSendMessage(IntPtr hServer, int sessionId, [MarshalAs(UnmanagedType.LPTStr)] string title, int titleLength, [MarshalAs(UnmanagedType.LPTStr)] string message, int messageLength, int style, int timeout, out RemoteMessageBoxResult result, bool wait);