Home > Windows

Command Prompt Pops Up and Closes Randomly on Windows 11 [Fixed]

In this guide, we will show you various methods to fix the issue of Command Prompt pops up and then closes randomly on Windows 11, all within a matter of a couple of seconds. Issues with peripheral devices like mouse and keyboard not working along the expected lines, or problems with OS components such as Taskbar and Start Menu continuously crashing have been well documented across the web. However, recently a weird type of issue has started happening in the latest iteration of the OS.

Many users have reported that the CMD window opens and then suddenly closes within a second. Since it seems to pop up randomly at any instance, it becomes all the more challenging in finding the root cause of this problem. if you are also getting bugged with this issue, then fret not. In this guide, we will make you aware of various methods to fix the issue of Command Prompt pops up and closes randomly on Windows 11. So without any further ado, let’s get started.

How to Fix Command Prompt Pops Up and Closes on Windows 11

fix Command Prompt Pops Up and Closes Randomly on Windows 11

After doing a thorough investigation of this issue, we found that missing system environment path variable path, corrupt background task schedulers, malicious third party programs, or corrupted Windows images are some of the most common causes. So in this guide, we will be addressing all these plausible reasons which in turn will end up rectifying the CMD issue as well. Follow along.

FIX 1: Use DISM Command

DISM or Deployment Image Servicing and Management is a command-line tool that checks the system for all the corrupt Windows mages files and then replaces them with their working counterpart. So let’s put this tool to test right away:

  1. Head over to the Start Menu, search CMD, and launch Command Prompt as an administrator.
  2. Then execute the following three commands, one at a time, in the CMD window:
    DISM.exe /Online /Cleanup-image /Scanhealth
    DISM.exe /Online /Cleanup-image /Restorehealth
    DISM.exe /online /cleanup-image /startcomponentcleanup

The scanning and fixing of corrupt system files might take a few minutes. Once done, restart your PC and then check if the issue of Command Prompt pops up and closes randomly on Windows 11 has been fixed or not.

FIX 2: Add Missing Environmental Variables

In case an environment variable is missing a PATH (such as C:\Windows\SysWow64\) then the CMD will keep on trying to search that path, but in vain. As a result, it might end up in a bootloop. The only way out is to add that missing path so that the Command Prompt is able to read it for once and then stops its background scan, for good. Here’s how it could be done:

  1. To begin with, use the Windows+R shortcut keys to open the Run dialog box.
  2. Then type in the below keyword and hit Enter. It shall open the System Properties menu.
    sysdm.cpl
  3. Now go to its Advanced tab and click on the Environment Variables button.
    Command Prompt Pops Up and Closes Randomly on Windows 11
  4. Select Path under System variables and click on the Edit button.
    Command Prompt Pops Up and Closes Randomly on Windows 11
  5. Now click on the New button.
    Command Prompt Pops Up and Closes Randomly on Windows 11
  6. After that, add the below value and click OK to save it.
    C:\Windows\SysWow64\

    Command Prompt Pops Up and Closes Randomly on Windows 11

  7. Finally, reboot your PC and then verify if it fixes the Command Prompt pops up and closes randomly on Windows 11.

FIX 3: Scan via Windows Defender

It could well be the case that a harmful application or program (or even an autorun key) could be using the CMD window to run its script in the backend. The only way to verify it and more importantly prevent it from happening is to scan your PC via antivirus software.

While you are free to choose any of your choices, but make sure to perform an in-depth scan, one that encapsulates the entire C drive at the very least. As for this guide, we will be proceeding ahead with Mircosoft’s built-in app. Follow along.

  1. Open the Virus and Threat Protection app via the Start menu.
  2. Then click on Scan Options under Current Threats.
    Command Prompt Pops Up and Closes Randomly on Windows 11
  3. After that select Full Scan and click on Scan Now.
    Command Prompt Pops Up and Closes Randomly on Windows 11

The scanning process will take some time. Once done. check if it was able to fix the issue of Command Prompt pops up and closes randomly on your Windows 11 PC.

FIX 4: Disable App Background Schedule

In some cases, a third-party app might be running its schedule in the background via the Command Prompt. In my case, it was one of the OneDrive’s services that was set to be automatically invoked after every one hour- for an indefinite time period!

So you should first verify whether there’s an app or service that is being invoked at regular intervals but could also work well and good even without that. And if there’s such an app, then you should consider disabling its automated schedule. Here’s how:

  1. To begin with, use the Windows+R shortcut keys to launch the Run dialog box.
  2. Then type in the below command and hit Enter to launch the Task Scheduler
    taskschd.msc
  3. Now expand Task Scheduler Local and select Task Scheduler Library.
  4. Look at the right-hand side and check out the list of all the apps.
    Command Prompt Pops Up and Closes Randomly on Windows 11
  5. If you find any that has been slated to run multiple times per day but probably shouldn’t be doing so,  then right-click on that app and select Disable. Do so for all the apps belonging to the same domain.
  6. Moreover, if you are using Microsoft Office Suite, then you should consider disabling one of its services as well. For that, select the following location from the left menu bar:
    Task Scheduler (Local) > Task Scheduler Library > Microsoft > Office
  7. Once you reach the Office folder, go to the right-hand side and select the OfficeBackgroundTaskHandlerRegistration.
  8. Then right-click on it and select Disable. Once done, restart your PC and then check if the Command Prompt pops up and closes randomly on Windows 11 has been fixed or not.

FIX 5: Delete SoundMixer Registry Value

Some users gave us a tip that a particular type of virus managed to escape from all the antivirus scans and had managed to get access to the Registry editor. Named SoundMixer, it is basically a crypto-mining autorun key that modifies the registry entries so that they could invoke the CMD window at regular intervals.

To rectify it, you just need to delete the SoundMixer entry, but that might prove to be easier said than done. This is because there is no fixed location where it might be located, you will have to first search it and then subsequently remove it. Here’s how:

  1. Head over to the Start Menu and launch Registry Editor.
  2. Then click on Edit from the top menu bar and select Find.
    Command Prompt Pops Up and Closes Randomly on Windows 11
  3. Now type in SOUNDMIXER in the space provided and checkmark all the three options: Keys, Values, and Data.
    Command Prompt Pops Up and Closes Randomly on Windows 11
  4. After that, uncheck “Match whole string only” and hit the Find Next button. Wait for the scan to complete.
  5. If it is able to find the SOUNDMIXER key or DWord File, then select it and refer to the right-hand menu.
  6. You should now see an AutoRun file associated with SOUNDMIXER, right-click on it, and hit Delete.
    Command Prompt Pops Up and Closes Randomly on Windows 11
  7. Then again continue with your search and delete all the remaining SOUNDMIXER entries.
  8. Once done, restart your PC and the CMD issue should now have been rectified.

So with this, we round off the guide on how you could fix the issue of Command Prompt pops up and closes randomly on Windows 11. We have shared five different fixes for the same. Do let us know in the comments section which one spelled out success for you. Likewise, all your queries are welcomed in the comments below.


Share: