MODE - CMD


Overview

The MODE command in Windows Command Line (CMD) is a versatile tool used to configure system devices, specifically printers and serial ports. It can control the redirection of printing jobs, display or alter the settings of connected devices, and adjust the properties of the console’s display. This command is particularly useful for system administrators and power users who need to manage device settings and troubleshoot device connectivity issues.

Syntax

The MODE command has several syntax forms, depending on what device settings or status information one needs to access or configure:

MODE
MODE CON[:] [COLS=c] [LINES=n]
MODE device [baud=b] [parity=p] [data=d] [stop=s] [xon=x] [octs=on|off] [odsr=on|off] [idtr=on|off]
MODE device [/STATUS]
MODE LPTn[:]=COMm[:]
  • CON[:]: Configure the console display.
  • device: Specify a device name for configuration (serial ports as COMn or printers as LPTn).
  • LPTn[:]=COMm[:]: Redirect printer output.

Parameters:

  • COLS=c: Sets the number of columns for the display console.
  • LINES=n: Sets the number of lines for the display console.
  • Various serial parameters like baud, parity, data, stop, and others control serial device communication settings.

Options/Flags

  • /STATUS: Provides the status of the specified device, very informative for troubleshooting.
  • COLS=c: Adjusts the width of the console’s output screen.
  • LINES=n: Modifies the height of the display in the command prompt window.

Examples

  1. Display configuration of all connected devices:
    MODE
    
  2. Set the display mode of the console:
    MODE CON: COLS=80 LINES=25
    
  3. Configure a serial port (COM1):
    MODE COM1: baud=9600 parity=n data=8 stop=1
    
  4. Check the status of a serial port (COM1):
    MODE COM1: /STATUS
    
  5. Redirect printing from LPT1 to COM3:
    MODE LPT1=COM3:
    

Common Issues

  • Permission Errors: Make sure you have proper permissions to change settings, especially in enterprise environments.
  • Invalid Parameters: Typographical errors in parameters can prevent the command from executing. Ensure all parameters are correctly typed.
  • Device Not Found: Ensure the device name is correct and the device is properly connected and enabled.

Integration

The MODE command can be integrated with batch scripts to automate setup processes or part of a troubleshooting routine. Combine with ECHO to log outputs in batch files.

Example of a simple script to configure and test a serial device:

@ECHO OFF
MODE COM1: baud=115200 parity=n data=8 stop=1
MODE COM1: /STATUS
IF ERRORLEVEL 1 ECHO Error configuring COM1
  • COPY: Useful for redirecting data to devices when combined with MODE.
  • ECHO: Can be redirected to print to different devices after using MODE to configure them.
  • CHCP: Display or set the active code page number. Useful for ensuring correct character encoding with certain devices.

For further details and advanced configuration options, consult the official Microsoft documentation for the command prompt and CMD scripting.