To fix Command Prompt closing immediately, run it as administrator, disable Quick Edit mode, or launch it via a batch file with a pause command—this keeps the window open after executing commands.

What You'll Need

  • A Windows PC (Windows 10 or 11 recommended)
  • Administrator access to the system
  • Basic familiarity with navigating folders and files
  • Notepad (built-in) for creating a batch file

Step-by-Step

  1. Press Win + R, type cmd, then hold Ctrl + Shift and press Enter to open Command Prompt as administrator. If the window stays open, the issue was due to insufficient permissions.
  2. If it still closes, right-click the Command Prompt title bar, select Properties, go to the Options tab, and uncheck Quick Edit Mode. Click OK. This prevents accidental clicks from closing the window.
  3. Open Notepad and type: cmd /k. Save the file as keepcmd.bat on your Desktop, ensuring the file type is set to All Files.
  4. Double-click the keepcmd.bat file. This launches Command Prompt with the /k switch, which keeps the window open after execution.
  5. To make this permanent, right-click the Desktop shortcut, select Properties, go to the Shortcut tab, and in the Target field, ensure it reads: C:\Windows\System32\cmd.exe /k. Click Apply, then OK.
  6. Alternatively, press Win + X and choose Windows Terminal (if available) or Command Prompt from the menu—these often stay open by default unless launched from a script that exits.
  7. If using a shortcut from the Start menu, right-click it, select Open file location, then right-click the shortcut again, choose Properties, and verify the Target ends with cmd.exe (no extra parameters like /c that close it).
  8. Check for malware: run a full scan with Windows Security (Settings > Privacy & Security > Windows Security > Virus & threat protection) as some malicious scripts force cmd to close.
  9. Update Windows: go to Settings > Windows Update and install all available updates—older versions may have bugs affecting console behavior.

Common Mistakes

  • Assuming the window closes due to a system error when it's actually closing normally after running a command—this is expected behavior unless you use /k or pause.
  • Editing the wrong shortcut (e.g., a desktop icon instead of the Start menu version) and wondering why changes don’t apply.
  • Disabling Quick Edit Mode but forgetting to click OK in Properties, so the setting isn’t saved.
  • Saving the batch file as keepcmd.txt instead of keepcmd.bat because Notepad hides extensions by default—always verify the file type.
  • Using cmd /c in a shortcut, which explicitly tells Command Prompt to close after running the command—use /k to keep it open.
  • Overlooking that some third-party software (like certain antivirus or keyboard remappers) can interfere with console windows.

Tips

  • Use pause at the end of a batch file to keep the window open until you press a key—e.g., echo Hello & pause.
  • If you frequently need Command Prompt, pin it to the taskbar: open it, right-click the icon, and choose Pin to taskbar.
  • For developers, consider using Windows Terminal or PowerShell instead—they offer better persistence and customization.
  • Create a dedicated folder for your batch files and add it to the system PATH for easy access from any Command Prompt window.
  • If the window flashes and disappears too fast to read, add a timeout /t 10 command to pause for 10 seconds before closing.
  • Check Group Policy (gpedit.msc) under User Configuration > Administrative Templates > System for policies that might restrict cmd.exe—though this is rare on home editions.

Troubleshooting

  1. If Command Prompt still closes immediately after trying the above, restart your PC—temporary glitches can affect console handling.
  2. Boot into Safe Mode (Settings > System > Recovery > Advanced startup) and test Command Prompt there. If it works, a third-party app is likely causing the issue.
  3. Perform a clean boot: press Win + R, type msconfig, go to Services, check Hide all Microsoft services, click Disable all, then go to Startup and open Task Manager to disable all startup items. Restart and test.
  4. Run sfc /scannow in Command Prompt (if you can open it briefly) to repair system files. If it closes too fast, use the batch file method from Step 3 to keep it open long enough to run the command.
  5. Check for corrupted user profile: create a new local user (Settings > Accounts > Family & other users) and test Command Prompt there. If it works, migrate your data to the new profile.
  6. As a last resort, run a Windows Repair Install: download the Media Creation Tool, run it, and choose Upgrade this PC now—this reinstalls Windows while keeping files and apps.

Frequently Asked Questions

Why does Command Prompt close right after I open it?

It likely closes because it’s being launched with a /c switch (which runs a command and exits) or via a script that ends immediately. Use /k or add pause to keep it open.

Can I make Command Prompt stay open by default for all shortcuts?

Yes—modify the Target field of any Command Prompt shortcut to include cmd.exe /k instead of just cmd.exe.

Is it safe to disable Quick Edit Mode?

Yes—it only prevents accidental text selection with the mouse from triggering a window close; it doesn’t affect security or system stability.

What’s the difference between /k and /c in Command Prompt?

/k carries out the command and keeps the window open; /c carries out the command and then closes the window—this is the default for many automated launches.

Will using a batch file to keep Command Prompt open use more system resources?

No—cmd /k or pause uses negligible memory and CPU; the console is idle until you interact with it.

Can Group Policy prevent Command Prompt from staying open?

Yes, in enterprise environments, policies like Prevent access to the command prompt can disable it entirely—but this usually blocks access, not just causes it to close.