This documentation is archived and is not being maintained.

How to: Control the Command Window

The CommandWindow object represents the Command window in the Visual Studio automation model. You can use the CommandWindow object to:

  • Insert a command into the Command window and, optionally, execute it by using the SendInput method.

  • Insert informational text into the Command window by using the OutputString method.

  • Clear all text from the Command window by using the Clear method.

In addition to controlling the contents of the Command window, you can also control its characteristics, such as width and height. For more information, see How to: Change Window Characteristics.


The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. These procedures were developed with the General Development Settings active. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

This example demonstrates how to reference and use the various members of the Command window automation model. For more information about how to run the example, see How to: Compile and Run the Automation Object Model Code Examples.

public void OnConnection(object application, ext_ConnectMode 
  connectMode, object addInInst, ref Array custom)
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.

public void CommandWinExample(DTE2 dte)
        // Get a reference to the Command window.
        CommandWindow CW = dte.ToolWindows.CommandWindow;

        // Insert informative text into the Command window.
        CW.OutputString("This takes you to the Microsoft Web site.");

        // Add a command to the Command window and execute it.
        CW.SendInput("nav", true);

        // Clear the contents of the Command window.
        System.Windows.Forms.MessageBox.Show("Clearing the Command 
    catch (Exception ex)