Home » Windows » 13 Fixes for Command Prompt (CMD) Opening and Closing Automatically

13 Fixes for Command Prompt (CMD) Opening and Closing Automatically

by Gaurav Bidasaria
Fixes for Command Prompt (CMD) Opening and Closing Automatically

You boot your Windows computer or wake it up from hibernation and notice the CMD or the Command Prompt flash for a fraction of a second. Now you are wondering what was that. You didn’t have the CMD open last time nor did you open or close it now so what’s happening here? Why is Command Prompt opening and then closing again automatically? Allow us to explain along with some solutions.

1. Scheduled Office Task Is Running

This is probably the most common reason and where you should begin looking. A scheduled task for Microsoft Office might be running in the background leading to CMD flash momentarily on the screen. Here’s how you can check that:

1. Press the Windows icon, search for Task Scheduler, and open it.

task scheduler in windows computer

Some users reported they were unable to open the Task Scheduler this way. In that case, search for and open MMC (Microsoft Management Console). Click on File > Add/Remove Snap-in. You will see several options. Find and open Task Scheduler from here.

open windows task scheduler from MMC

2. From the left sidebar, drill down to the folder structure – Task Scheduler Library > Microsoft > Office. In the right window pane, right-click on OfficeBackgroundTaskHandlerRegistration and Disable it.

disable windows office task scheduler

2. Keep CMD Open

The problem when the Command Prompt opens and closes quickly is that before you can see what’s happening, it disappears. A Microsoft user found a solution where you can keep the CMD open so you know what is happening.

1. Open elevated Command Prompt. To do that, search for CMD and click on Run as administrator option.

open cmd with admin rights

2. Copy-paste the command below and press Enter to run it.

cmd /k netstat

You can close the CMD now.

3. Automatic Maintenance Tasks

Windows runs several maintenance tasks in the background like updating OS, updating Microsoft Store apps, time and date, weather, and so on. These tasks run in the background, however, CMD may appear briefly and then disappear when one of these tasks runs. You can check a list of such tasks in PowerShell.

1. Open PowerShell with admin rights from the Start menu.

open windows powershell with admin rights

2. Simply copy-paste the command below to see a list of maintenance tasks.

Get-ScheduledTask | ? {$_.Settings.MaintenanceSettings}
list of automated maintenance tasks in windows

You will see the names of the tasks, the path to the file or app name, and whether it is enabled or disabled.

4. Change Name of CMD.exe File

CMD is an executable file. Renaming this file after creating a copy has helped fix the problem for many users.

1. Drill down to the folder structure below and find the CMD app in the list.

Local Disk (C:) -> Windows -> System32
cmd app in windows

2. Now simply create a copy of the CMD file using the Ctrl+C and Ctrl+V keyboard shortcuts. Rename the original to something else like CMD-old and then rename the copy to CMD. We recommend you backup the original (now renamed to cmd.old) to a pen drive just in case you need to restore it.

5. Scan for Virus, Malware

It is possible that hackers have gained control or access to your Windows PC and are running commands. Scary situation but not unlikely these days.

Run Defender or 3rd-party antivirus software that you may have installed. Don’t select quick scan but instead perform a full scan. It may take some time but you don’t want to skim on this.

1. To run Defender, open Windows Security > Virus & threat protection.

open virus and threat protection from windows security in windows pc

2. Click on Scan options.

windows security scan options

3. Select Full scan and click on Scan now button below.

run full scan for windows security defender

6. Run Microsoft Safety Scanner

Safety Scanner, unlike Defender and other security features in Windows Security, doesn’t come preinstalled. You have to download it fresh every time you want to run it. That’s because it is updated every week.

Simply Download Microsoft Safety Scanner and double-click to open and run it. Use the computer normally or reboot it once to check if Command Prompt opens and closes automatically again.

7. Run Malwarebytes

This is the last time we will ask you to run a threat scanner in this article. Promise. While Defender is good at protecting Windows PCs from viruses, malware is a different beast. Download and run the free version of Malwarebytes. Again, do a full scan.

Download Malwarebytes

8. Run SFC

SFC or System File Checker will check the integrity of the system files that are critical for running the Windows OS.

1. Open CMD with admin rights again as we did above in section 2.

open cmd with admin rights

2. Copy-paste the commands below, one at a time, and in the same order they are mentioned.

DISM.exe /Online /Cleanup-image /Restorehealth
sfc /scannow

It may take some time for both the commands to run its course. You will see 100% once the SFC scan is complete.

9. Check Startup Folders

Now that we have ruled out that the PC is not hacked or compromised in any way, let’s move on to startup folders. It contains a list of all the apps that are scheduled to run or launch when Windows computer is booted for the first time. One of these apps may be using CMD in the background.

Pro Tip: Disallowing some apps from running on startup can improve the time it takes to start the computer and improve performance as fewer apps are running in the background.

1. Press Windows key+R to open the Run prompt and type the command below and hit Enter.

open startup folder using run prompt

2. A folder will open. You can delete any CMD or Command Prompt related entries here. In our case, the folder is empty but it differs from PC to PC as each one is configured differently.

startup folder in windows

10. Check Startup Apps

Some apps run automatically in the background even when you are not using them actively or haven’t even opened them. That’s because they are programmed to open when you start or restart the PC. This also makes the computer slow as unnecessary resources are consumed in the background to run these apps.

1. Press Ctrl+Shift+Esc keys on the keyboard to open the Task Manager.

2. Go to Startup apps from the left sidebar. You will see a list of apps. Check the Status column. If it is enabled, the app will launch in the background when Windows starts. If you see any entry related to CMD, right-click on it and select Disable.

disable startup apps from task manager in windows

11. Check Using Autoruns

Autoruns is a utility tool from Microsoft that will show you a list of all the tasks and processes that run automatically without user input. A good way to find hidden or rogue apps that are running in the background without your knowledge. You will need to download it separately though. The link is below.

For example, it shows that we have NZXT Cam, a gaming app running in the background and is scheduled to run automatically. But it comes in handy only when you are gaming so it’s a waste of resources. A good way to do some house cleaning and check all the autoruns.

Download Autoruns

12. Use PowerShell or Terminal Instead

Command Prompt has been succeeded by PowerShell and now, Terminal. These two command utilities do everything that the humble CMD does and then even more. The UI is also more user-friendly with multiple tabs, color-coded commands/results, and more.

We have an in-depth guide on how these three command utilities differ and another good source on how to use Terminal best.

13. Clean Boot

You can perform a clean boot to find out if an app is causing this. Sometimes, contradictory apps cause all sorts of problems including the one you are facing where CMD opens and then closes automatically.

Take Command

More often than not, the Command Prompt opening and closing automatically on its own is a task that’s running in the background. You don’t have to worry if it happens once or twice and then doesn’t. If it happens again, make sure your computer is not infected. Thoroughly scan the system as we described above.

You may also like