When I open the command prompt, it automatically closes itself after 2-3 seconds. Can anyone help me why Command Prompt in Windows 7 automatically hides after 2-3 seconds?


You could have a virus running on the system that is closing the command prompt, in order to make it more difficult for you to remove the virus.

Perhaps it is killing processes that are named cmd.exe. I suggest that you make a copy of cmd.exe and call it abcd.exe. Then run abcd.exe and see if it keeps running.

  • 2
    +1, I've only seen this behaviour when I've had some virus. Also try to run Regedit and see if it does the same. – Hondalex Aug 3 '10 at 14:16
  • I have seen this virus on XP. Didn't expect to see this one on 7. – user May 15 '11 at 8:20

If you are writing a program that executes on the command line, and running it directly from your IDE, not by typing the program name in manually, the command prompt window will close as soon as the program finishes executing. To avoid this, either manually open a command prompt, entering the executable name to run it, or stick a getchar call or equivalent at the end of your program.

  • I have just opened the command prompt by writing cmd.exe. When it opens up after 2-3 seconds it automatically close by itself don't know why? – Rashim Aug 3 '10 at 7:31

Are you using Windows 7 build 7000 ? According to this topic, there are known bugs in that build for command prompt and network drives. You can check build version by opening up cmd, see image :

enter image description here

As you see my windows 7 build version is 7601. The lastest version so far. So if your version is before 7601, I suggest you to update to the lastest version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy