In windows, alt+F4 does not close cmd (As in: WindowsKey+R, cmd, Enter)

How different is the command window from a normal window?

  • There are some third-party hotkey handling programs out there. Some should be able to intercept Alt-F4 only for the relevant command-prompt windows, and use an alternative shutdown (e.g. type "exit", or click the close button, or use the system menu "close" option). Obviously, you should be aware of the possible downside (see Jeffs answer). Sorry, I can't make a recommendation. – Steve314 Dec 6 '11 at 23:50
  • you can use Alt+Space -> C to close it. – Bor691 Sep 3 '16 at 12:02

The command window uses those key combination for varies applications within the dos emulating window. If Alt-F4 closed the window, it may be impossible to use certain utilities. If you want a keyboard only fix just type exit to quit.

  • what certain utilities ? Alt-F4 close almost all the windows in NT Systems, then why command prompt is an exception ? – Peeyush Sep 3 '12 at 5:19
  • 1
    Applications before Windows NT in DOS. I remember one game where Alt+F4 brought up the save menu for a game (Wing Commander Armada I believe). Since this is designed to Emulate(or display) DOS it must accept this key combination and not close so these apps can receive the command. – Jeff F. Sep 4 '12 at 18:12
  • oh.. Okay... So Microsoft must be still using that combination for some functionality, otherwise they must have provided support by now. – Peeyush Sep 5 '12 at 5:29

On the other hand, if you are looking to have Alt+F4 close the console window, you can use the following AutoHotkey script:

#IfWinActive, ahk_class ConsoleWindowClass
    !F4::WinClose, A


Alt+F4 sends the program with focus the WM_CLOSE message.

So, the cmd program is either intentionally configured to ignore WM_CLOSE messages, or possibly doesn't process any messages at all.

  • This does not entirely apply to Win32 Console windows - they're owned by conhost (earlier - by csrss), and console applications handle it differently. – user1686 Jan 20 '11 at 14:44
  • @grawity, duly noted, thanks. But it sounds like that could be the start of the real answer to the question. – DMA57361 Jan 20 '11 at 21:13
  • @grawity - I thought within windows, there was still a WM_CLOSE message handled as part of the console program. Not that it makes much difference, though - this is an answer for programmers working on the source of cmd.exe, not for users curious about the design rationale. – Steve314 Dec 6 '11 at 23:45
  • 1
    As you can see with iglvzx’s answer, consoles do indeed close in response to WM_CLOSE. – Synetech Mar 20 '12 at 17:54

Windows 10 Command Prompt Can Be Closed using ALT+F4 Hotkey claims that this problem affects only Windows up to 8.1.

Windows 10 Command Prompt duly responds to ALT+F4

It also mentions that Alt + F4 can be disabled in Windows 10 to mimick the old behaviour by creating a registry key REG_DWORD AllowAltF4Close set to 0 in HKEY_CURRENT_USER\Console.

  • Unfortunately, switching to windows 10 fixes only cmd windows. Powershell ones still ignore ALT+F4. – user185953 Jul 30 '20 at 11:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.