How to Close Command Prompt: Step-by-Step Guide
In this article
To close Command Prompt, click the X button in the top-right corner of its window, type exit and press Enter, or press Alt+F4 while the window is active. If a program or script is still running inside it, you may need to confirm with Y or stop the process first. This guide covers every standard way to close Command Prompt on Windows, plus what to do when it refuses to close.
What You'll Need
- A Windows PC with Command Prompt open (any recent version: Windows 10 or 11).
- Keyboard and mouse (or touchscreen).
- Administrator permission only if you need to close a Command Prompt window opened by another user or a system process.
Step-by-Step
- Try the X button first. Click the close button (the X) in the top-right corner of the Command Prompt window. This is the simplest method and works unless a process is blocking the close.
- Use the exit command. Click inside the Command Prompt window, type
exit, and press Enter. The window closes immediately. This is the cleanest way because it lets any running batch script finish its current command before closing. - Press Alt+F4. Make sure the Command Prompt window is the active window (click its title bar), then press Alt+F4. This sends a close request to the window, same as clicking X.
- Use Task Manager if the window is frozen. Press Ctrl+Shift+Esc to open Task Manager. On Windows 11, click the Processes tab (it may be called Details in some versions). Find Windows Command Processor or cmd.exe in the list, select it, and click End task. On Windows 10, the button is also End task. Confirm if prompted. Note that ending the task forcefully closes all Command Prompt windows, not just the frozen one.
- Close all Command Prompt windows at once. If you have several open, you can close them individually with the methods above, or use Task Manager to end the Windows Command Processor process group. Be aware this also closes any scripts running in those windows.
- Handle a script that is waiting for input. If a batch file or command is paused (for example, waiting for you to press a key or type Y/N), the window may not close with X. Press Ctrl+C to interrupt the running command, then type
exitand press Enter. - Close an elevated (administrator) Command Prompt. The same methods work. If you opened it with "Run as administrator," closing it may prompt for confirmation if a process is still running; click End process or Yes.
Menu labels and button names can differ slightly between Windows versions and editions, but the core methods above are consistent across Windows 10 and 11.
Common Mistakes
- Clicking X while a script is running. This can leave the script half-finished or lock files. Prefer typing
exitor pressing Ctrl+C first. - Using Alt+F4 on the wrong window. If Command Prompt is not active, Alt+F4 closes whatever window is active instead. Always click the Command Prompt title bar first.
- Ending the wrong process in Task Manager. "Windows Command Processor" is the safe target. Ending "Windows Explorer" will close your taskbar and desktop icons, not Command Prompt.
- Assuming the window is frozen when it is just waiting. A blinking cursor with no prompt often means a command is still running. Press Ctrl+C to cancel it before trying to close.
- Forgetting about background Command Prompt windows. Some installers or scripts open a hidden or minimized Command Prompt. Check the taskbar and Task Manager if you are not sure.
Tips
- Type
exitrather than clicking X when you have run commands that changed system settings; it gives the shell a chance to flush any pending output. - You can close Command Prompt from within a batch file by adding
exitas the last line, but only if you want the window to close automatically. - If you use Windows Terminal (the default console host on Windows 11), closing a tab with the X on the tab or Ctrl+Shift+W closes only that tab; closing the whole window closes all tabs.
- Pin Command Prompt to the taskbar if you open it often; right-click its taskbar icon and choose Close window to close all instances at once.
- To avoid accidentally closing a window with unsaved command history, use the
doskey /historycommand to review recent commands before exiting.
Troubleshooting
If Command Prompt does not close with X, Alt+F4, or exit, work through these steps in order:
- Press Ctrl+C. This interrupts most running commands. Then try
exitagain. - Check for a "Press any key to continue" prompt. Press any key, then type
exit. - Close child processes. Some commands (like
pingwith a high count, or a Python script) keep the window busy. Open Task Manager, find the specific process under Windows Command Processor, and end it. - Restart Windows Explorer. In Task Manager, find Windows Explorer, right-click it, and choose Restart. This can clear a stuck window without rebooting.
- Sign out and back in. If the window still will not close, sign out of Windows (Start > user icon > Sign out) and sign back in. This closes all user processes, including Command Prompt. Save your work in other apps first.
- Restart the PC. As a last resort, restart the computer. This closes all Command Prompt windows and clears any stuck state. No data is lost beyond unsaved command output.
If the window closes but immediately reopens, a startup script or scheduled task is launching it. Check Task Scheduler and your Startup folder (shell:startup) for entries that run cmd.exe.
Frequently Asked Questions
Does closing Command Prompt stop a running script?
Yes. Closing the window terminates the command processor and any child processes it started. For a graceful stop, press Ctrl+C first.
How do I close Command Prompt without a mouse?
Press Alt+F4 while the window is active, or type exit and press Enter. Both work entirely from the keyboard.
Why does my Command Prompt window close immediately after opening?
This usually means a startup script or shortcut is running a command that finishes instantly. Check the shortcut's target and any scheduled tasks that launch cmd.exe.
Can I close Command Prompt from another Command Prompt?
Not directly by window. You can use taskkill /IM cmd.exe to end all Command Prompt processes, but this closes every cmd window, including the one you are typing in.
What is the difference between closing Command Prompt and exiting a batch file?
Closing the window ends the entire session. Exiting a batch file (with exit or by reaching the end) returns you to the prompt if the batch was called from an open window, or closes the window if the batch was launched in its own window.
Does closing Command Prompt with X lose my command history?
Yes, the in-memory history is lost unless you saved it. Use doskey /history to view it before closing, or redirect output to a file.