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.