Workplace IT

How to close command prompt using the exit command

Close Command Prompt with the exit command, including the /B option and exit codes for batch scripts.

· 1 min read
Illustration of a terminal window with a close mark

Do you know the “proper” way to close the command prompt?

If your answer was “yes, press the x button” then read on to learn how to close the command prompt window like a professional.

Open Command Prompt as Administrator

Windows search results for Command Prompt with Run as administrator

  1. Press the Windows Key
  2. Type cmd and press return
  3. Right Click the Command Prompt icon and select ‘ Run as Administrator’

Type the command

In the command prompt window enter the below command and press return

exit

And as if by magic, the command prompt window will close

Command Prompt window with the exit command typed at the prompt

exit command options

The exit command has a few additional options that are primarily intended to be used if executing a batch script or applying an error level

EXIT [/B] [exitCode]

/B specifies to exit the current batch script instead of CMD.EXE. If executed from outside a batch script, it will quit CMD.EXE

exitCode specifies a numeric number. if /B is specified, sets ERRORLEVEL that number. If quitting CMD.EXE, sets the process exit code with that number.

LewisA cheeky geek, who loves a good side project. A proven IT leader with multiple strings in his bow. Particularly interested in implementing technology to streamline workloads, always on the lookout to automate processes and save time.

Keep reading