Everyone knows that the Alt + F4 keyboard shortcuts terminate the program, or rather disable the first window, and the Ctrl + Alt + DEL keyboard shortcuts call the task manager.

Is it possible to write code that, when the program is running, did not respond to these shortcut keys, or did the box give messages in the message?

    2 answers 2

    Alt + F4 only sends a WM_CLOSE message to the WM_CLOSE . The program may respond to this message by closing the window, or it may not.

    Ctrl + Alt + Del is processed by the system and is not sent to applications. In order to intervene in his work, you will have to, I am afraid, descend to the level of the keyboard driver.


    As for Ctrl + Alt + Del, here is the translation of the answer from serverfault :

    The Windows kernel (NT) is arranged in this way: it reserves notification of this key combination only for the Winlogon system process. Thus, if Windows is working correctly, then no user application can handle this key combination. If it could, it could show the fake login screen to the user and thus intercept his password;)


    This article says that

    It is impossible to mimic the Ctrl-Alt-Del SendKeys using SendKeys . Pressing Ctrl-Alt-Del causes a hardware interrupt, through a direct separate wire on the keyboard.

    That is, and intercept it from Windows will not work.

    Humble yourself.

    • The keyboard driver does not help, I checked, except that there is coca, then that specific "feint with ears" about which I personally will be interested to know. - Mirdin
    • Hm I wonder if this is true: northcode.com/blog.php/2007/07/25/… - VladD
    • Maybe I translate incorrectly, but there about assigning a shortcut key instead of CTRL + ALT + DEL and there is the phrase "CTRL + ALT + DEL to get there. " to the hooks in my article has nothing to do. - Mirdin
    • @Mirdin: yep. But they do not descend to the driver level, they are purely user-mode. - VladD
    • 2
      @Qwertiy: I just asked. He says that the Ctrl-Alt-Del key combination generates a special interrupt on the BIOS level (or the keyboard itself, does not remember), which is separate only for this key combination. It is signed by the operating system, and responds accordingly. There are no user hooks, you can only penetrate (by the driver) to the zero ring and forcibly unsubscribe the OS from interruption. But this is already a dirty hack, and will not receive a signature from Microsoft. - VladD

    I will not say about Alt + F4 , but as far as I know, it is impossible to put a hook on Ctrl + Alt + DEL , and accordingly you will not be able to attach any actions.

    PS In any case, all this is not done in c #, only C, only hardcore.

    • You can get to the message loop level in C # (easier, of course, in WinForms). - VladD
    • Yes you can, but "hemorrhoids", .Net - it's still a little bit about that, but in the level of "keyboard driver", here and the pluses do not quite fit - Mirdin
    • This is yes, there can not do without a pure C. Even C ++ doesn’t drive, probably. - VladD
    • @VladD, EMNIP there were some kind of, third-party, in my opinion, libraries, such as the first C ++, still with the translation, but they did not always work, but I’d not say specifically, "it was a long time ago." - Mirdin