How to Fix Command Prompt Automatically Opens and Closes at Windows 11 Startup

CMD Automatic Opening Closing Windows 11CMD Automatic Opening Closing Windows 11

You may be experiencing random sessions of Command Prompt automatically opening and closing on your new Windows 11 OS. Several users have reported this issue where occasionally several different CMD windows open and close simultaneously as soon as you log into your account, while others are reporting a random behavior of the command-line interface with no pattern.

Although your daily routine and tasks may not be greatly affected by this problem, it is still wise to resolve the issue so that you can enjoy the recently-released operating system to its fullest, especially if you have purchased a new device just for the sake of Windows 11.

This article lists down several reasons as well as its solutions to mitigate the Command Prompt flashing issue in Windows 11.

Causes of Command Prompt Fluctuation in Windows 11

There is no single reason for the Command Prompt to behave this way. Although the CMD windows close by themselves after a few seconds, why did they open automatically in the first place? Regular users pay little to no attention to such behavior of the OS, but some users may get annoyed if the Command Prompt pops up out of nowhere ruining their streaming or gaming experience.

Irrelevant task

If you have upgraded your device from Windows 10 to Windows 11, there may be a chance that you have brought along a migrated task that no longer servers a purpose in the new OS. Such unnecessary tasks can often cause irregular behavior of the operating system.

Missing Environment Variable Paths

Command Prompt automatically opening and closing can also be caused by missing the Environment Variable Path. Users who have upgraded their devices to Windows 11 rather than performing a clean install usually come across missing paths.

Background Office tasks

One cause can also be background Office Suite tasks that may be malfunctioning. If you see that the Command Prompt popups are occurring after every fixed interval, an Office scheduled task is likely causing it to behave this way.

Virus/Malware

One of the more common reasons for the Command Prompt behaving irregularly is due to unwanted malware on your computer. This can also be brought in through certain notorious web browser extensions. If you see a Command Prompt popup while using a browser, it is likely due to a malicious extension.

Discreet Crypto Mining

Some hidden tasks are programmed to perform crypto mining on your devices. Such programs can cause the Command Prompt to behave erratically.

These are the reasons for the Command Prompt opening and closing automatically on Windows 11 that we are aware of so far. Let us now see how you can resolve the issue.

Fix Command Prompt randomly opens and closes in Windows 11

Repair Windows image

You can try repairing your Windows image in case you upgraded to Windows 11 from an older OS. This method will clear out any unwanted tasks that are of no use anymore.

To do so, launch Command Prompt with administrative privileges and enter the following 3 commands, one after the other:

DISM.exe /Online /Cleanup-image /Scanhealth
DISM.exe /Online /Cleanup-image /Checkhealth
DISM.exe /Online /Cleanup-image /Restorehealth
DISM healthcheck
Repair Windows images using DISM

It can take a few minutes for the commands to execute completely. Do not close the Command Prompt and allow them ample time to run.

Once completed, spend some time on your computer to check if the Command Prompt still behaves the same. If it does, continue to perform the rest of the mitigation methods below.

Add missing Environment Variable path manually

As we mentioned earlier, users that have upgraded to Windows 11 can also experience missing Environment Variable paths. In this particular case, the path to “C:\Windows\SysWow64” is usually missing, which causes the Command Prompt to spontaneously open and close.

Here’s how to fix the issue:

  1. Open the System Properties window on your computer by typing in sysdm.cpl in Run.
    run
  2. In the System Properties window, switch to the Advanced tab and then click the Environment Variables button at the bottom.
    EV button
  3. Now click on Path under the System variables window, and then click Edit.
    path edit
  4. Next, in the Edit environment variable window, click New, then paste the following in the text field:
    C:\Windows\SysWow64\
    Then click OK on all windows to save and close them.
    add new
  5. Now restart your computer for the changes to take effect.

After the computer reboots, check to see if the issue persists. If it does, then the missing Environment Variable path is not your issue. Continue to read further for more possible solutions.

Disable any Office Suite scheduled tasks

If you see that the Command Prompt is opening and closing after every fixed interval, it is likely because of the Office Suite scheduled task(s) running in the background.

This issue was reported to have been around for quite some time and was the same on Windows 10 as well. However, the fix for it on Windows 11 is the same: end the scheduled task causing CMD to behave this way. Here is how to do so:

  1. Open the Task Scheduler by typing in taskschd.msc in Run.
    taskschd in run
  2. Now navigate to the following location from the left pane inside the Task Scheduler:
    Task Scheduler (local) >> Task Scheduler Library >> Microsoft >> Office
  3. Now right-click the task OfficeBackgroundTaskHandlerRegistration in the right-hand pane, and then click End from the context menu.
    end
  4. Once done, restart your computer so the changes can take effect.

The Command Prompt will no longer automatically open or close if it is caused by Microsoft Office’s scheduled task.

Scan computer for malware

Another likely cause for the Command Prompt to behave abnormally is due to malware or viruses in your computer. Therefore, it is recommended that you perform a deep system scan and get rid of any trojan horses or malware. Here is a list of the top antivirus software to use to perform the scan.

In case you are proceeding to purchase antivirus software, here are the 17 aspects you should always consider.

You can also use the built-in Windows Defender in Windows 11 to scan your computer for malware. If you want to, open the Windows Security page in the Settings app, and then click Virus & Threat Protection. Next, click the Quick Scan button to perform a scan. Alternatively, you can also click Scan options below it to select a deep scan of your OS.

scan
Virus and Threat protection

Delete crypto mining Windows Registry

Certain programs and tasks running in the background disguise themselves as legitimate Windows programs, but are using your computer to mine cryptocurrency to someone else.

One of the most notorious programs for crypto mining was the SoundMixer.exe. This process kept running in the background while nobody batted an eye. As it turns out, this process is used to mine for cryptocurrency without the user of the device knowing anything about it.

Such programs may occasionally go undetected by even the best antimalware software as they lie in a gray area of Windows operations and are very well coded/developed.

You will need to manually remove the associated Windows Registry so that no crypto mining program can run on your device if that is the case. However, manipulating Windows Registry could turn fatal for your OS. Therefore, we recommend that you create a restore point so that you can recover your device if things go south.

  1. Open the Registry Editor by typing in regedit in Run
    regedit run
  2. Now click Edit from the top menu and then click Find.
    find
  3. In the Find window, search for soundmixer and click Find Next.
    search sounmixer
    Since there is no one location for such viruses, it needs to be searched within the Windows Registries.
  4. If the results bring something back, look for Autorun value in the right pane, right-click it, and click Delete from the context menu.
    In case you do not find anything, you probably do not have a sound mixer on your computer.
  5. If you found and deleted the Autorun value from Windows Registry, restart the computer.

Once the device restarts, check to see if the Command Prompt still opens and closes automatically.

Why did Command Prompt randomly open and close?

This issue has been detected in both Windows 10 and Windows 11. The most common cause for the Command Prompt to randomly open and close is a background task running for Microsoft Office. While another common cause for Windows 11 is when you upgrade from an older OS and migrate irrelevant tasks or miss Environment Variable paths.

How do I open Command Prompt in Windows 11?

Although there are several ways to open the Command Prompt in Windows 11, the most convenient way is to use the Windows Key + R shortcut keys to launch Run, and then type in CMD, and press Enter.

Is cmd.exe a virus?

Although cmd.exe is a legitimate Windows process that runs against the Command Prompt, attackers often disguise the malware with legitimate process names so they can hide in plain sight.

If you liked this post, Share it on:
Subhan Zafar is an established IT professional with interests in Windows and Server infrastructure testing and research, and is currently working with Itechtics as a research consultant. He has studied Electrical Engineering and is also certified by Huawei (HCNA & HCNP Routing and Switching).

Leave the first comment

Get Updates in Your Inbox

Sign up for the regular updates and be the first to know about the latest tech information

Talk to us now

Talk to us straight and get your questions answered right away

Tell Us About Your Project