Command Prompt windows that close immediately after opening prevent users from running essential commands, disrupt troubleshooting, and sometimes impact other software that relies on CMD. This behavior on Windows 11 often points to a misconfigured registry, problematic startup entries, or interference from malware or third-party applications. Addressing the root cause restores normal access to CMD and improves overall system stability.

Delete the Autorun Value from the Windows Registry

Step 1: Open the Registry Editor by pressing Win + R, typing regedit, and pressing Enter. Approve any User Account Control prompts.

Step 2: Navigate to the following path in the Registry Editor:

HKEY_CURRENT_USER\Software\Microsoft\Command Processor

Step 3: In the right pane, look for a value named autorun. If it exists, right-click this value and select Delete. Confirm any prompts to remove it. This value can cause CMD to execute a command or script at launch, which may result in CMD closing instantly if the command is faulty or points to a missing file.

Step 4: Close the Registry Editor and restart your computer. Try opening Command Prompt again to check if the issue is resolved.


Scan for Malware and Viruses

Malware or unwanted programs can alter system behavior, including CMD window functionality. Running a thorough scan helps detect and remove problematic software.

Step 1: Open Windows Security by searching for Virus & threat protection in the Start menu.

Step 2: Click Scan options and select Full scan. Click Scan now to begin. Wait for the scan to complete and follow any prompts to quarantine or remove detected threats.

Step 3: For a second opinion, download and run a reputable third-party malware scanner such as Malwarebytes. Follow its instructions to scan and clean your system.

Once scans are complete, restart your PC and check if Command Prompt remains open after launching.


Remove CMD Shortcuts from Startup Folders

Startup entries can trigger CMD to open and close rapidly at login or during regular use. Removing unnecessary shortcuts prevents unwanted CMD windows from launching.

Step 1: Press Win + R, type shell:startup, and press Enter. This opens the user Startup folder.

Step 2: Look for any shortcuts related to cmd.exe or batch files (.bat, .cmd). Delete these shortcuts if they are not intentionally placed there by you.

Step 3: Repeat for the system-wide Startup folder by running shell:common startup in the Run dialog.

Restart your PC and see if the CMD window issue persists.


Some background applications or scheduled tasks can cause CMD to open and close automatically. Disabling unnecessary startup items can isolate the cause.

Step 1: Open Task Manager by pressing Ctrl + Shift + Esc and switch to the Startup tab.

Step 2: Review the list for any entries referencing cmd.exe, batch files, or unfamiliar applications. Right-click these entries and select Disable.

Step 3: Restart your PC and check if CMD opens normally.


Perform a Clean Boot to Identify Conflicting Software

A clean boot starts Windows with only essential drivers and services. This helps identify if third-party software is causing CMD to close immediately.

Step 1: Press Win + R, type msconfig, and press Enter.

Step 2: In the System Configuration window, go to the Services tab, check Hide all Microsoft services, then click Disable all.

Step 3: Switch to the Startup tab and click Open Task Manager. Disable all non-essential startup items.

Step 4: Close Task Manager, click OK in System Configuration, and restart your computer.

If CMD works after a clean boot, re-enable items one at a time to identify the offending program or service. Uninstall or update the problematic software as needed.


Check for Corrupted System Files

Corrupted system files can disrupt CMD functionality. System File Checker and DISM tools can repair these files.

Step 1: Open PowerShell as an administrator by searching for PowerShell, right-clicking it, and selecting Run as administrator.

Step 2: Run the following command to check and repair system files:

sfc /scannow

Step 3: After the scan completes, run the following DISM commands one by one:

DISM.exe /Online /Cleanup-image /Scanhealth
DISM.exe /Online /Cleanup-image /Restorehealth
DISM.exe /Online /Cleanup-image /StartComponentCleanup

Step 4: Restart your computer and test if Command Prompt opens correctly.


Create a New User Profile

If the above steps do not resolve the issue, the problem may be isolated to your user account. Creating a new profile can help determine if this is the case.

Step 1: Open Settings > Accounts > Other users.

Step 2: Click Add account to create a new user. Log in with the new account and test Command Prompt. If it works, consider migrating your files to the new profile.


Resolving the automatic closure of Command Prompt on Windows 11 often comes down to cleaning up registry autorun entries, disabling problematic startup programs, and scanning for malware. Regular maintenance and cautious installation of third-party software can help prevent this issue from recurring.