0

I have started to work on a small windows application.

 private void Form1_KeyDown_1(object sender, KeyEventArgs e)
        {
            if (e.Control && e.Alt && e.KeyCode == Keys.P)
            {
                MessageBox.Show("Hello");
            }
        }

The above code works fine.

I want to override the Alt+Ctrl+Del shortcut to show some message instead of the task manager.

How can i achieve this?

slava
  • 791
  • 1
  • 11
  • 26
backtrack
  • 7,996
  • 5
  • 52
  • 99
  • 2
    1. You can't do it, and 2. Don't do it, your users will expect that combination to do other things, dont disappoint them. – Sayse Jul 22 '14 at 06:03
  • Related with decent explanation: [Disable Ctrl+Alt+Del on Windows 7](http://stackoverflow.com/questions/11439317/disable-ctrlaltdel-on-windows-7) – Sayse Jul 22 '14 at 06:04
  • But i want to ensure that the user should not close my application. And the user should not kill my application through Task managger – backtrack Jul 22 '14 at 06:24
  • @Sayse i can understand it. But how to i ensure that the user is not closing my application while it is running – backtrack Jul 22 '14 at 06:25
  • Make your program beneficial to be running, you can't stop a user closing your application nor should you be trying to by trapping them into it. If you tried it on me I'd just hold that power button down, after changing my start up programs, and never use your application again. – Sayse Jul 22 '14 at 06:27
  • @Sayse My application is going to be a Login point of the system. Once the user log in it will minimize and the user can do all the things. But to ensure that the user is log in through my application i want to do this. – backtrack Jul 22 '14 at 06:32
  • You cannot do it... even [Bill Gates thought ctrl alt del was a mistake](http://www.bbc.co.uk/news/technology-24283185), FYI, Windows 8 now uses one key to show the login screen – Sayse Jul 22 '14 at 06:34
  • @Backtrack - look up Kiosk-Mode, that may be of help. Otherwise you will just have to write your own OS. – H H Jul 22 '14 at 07:04
  • You can disable task manager with group policy. – Harry Johnston Jul 23 '14 at 00:12

1 Answers1

3

Just don't. You can't, and you shouldn't. The comments stated this, but I thought it was worthy of putting down here.

I guess an important distinction is that you can listen to the combination, but you cannot override Windows' reaction to it.

Think about the reason for this well-known key combination, in a security sense: it is there to give logging in users confidence that they aren't about to type their password into some clever, phishing application. If Windows permitted you to override the functionality, you could easily write a full-screen, pretty, blue page that said "CTRL + ALT + DEL to unlock" (or whatever it actually says), then you could pop up a textbox, and users would willingly type in their password, and there you'd have it. But Windows doesn't want people doing that, and people don't want to do that. So it's disallowed.

As for why you shouldn't, there are a few reasons. First, people will be confused. They'll be looking for what key combination to press, see yours, and be instantly confused because of a preconceived notion of what it should do. Not only is it the opposite of discoverable, but it will be difficult for users to believe even after they see it written plainly out.

Secondly, when your application crashes ("but my applications will never crash!"--let me rephrase myself--when your application crashes), the user might want to press this well-known key combination to bring up Task Manager, or even something more serious, like to invoke a reboot. Here, there are two options: one, your application is responding well enough to not let the user do that, then that's awful. Two, your application is not responding well enough to not let the user do that, and they're now making a bet on that very lack of responsiveness (In other words, they have to assume that your application won't respond, and that's an uncomfortable assumption for both of you).

Another great reason to not do this is just the difference in scope. For one, users are used to this key combination as being a global, OS matter. What it means in one window, it means in another. Having that change out from under them would be similar to changing what, say, clicking the start menu does. It will be way-confusing, and just generally icky to use. By the same token, users might be confused when they go to use your app and, say, they've got the taskbar selected (or something), so they bring up that screen instead. It's also possible that users will be using a completely different application, and somehow think that yours is still listening, so they'll press the combination and, you guessed it, be confused.

Instead of doing something like this, you should find an alternative. Depending on what you want to do (honestly, I can't imagine why you'd want to do this aside from writing a phishing page, but I'll expect the best of you for the sake of argument), CTRL+break might be a good option. It tends to be a good, customizable way of saying "stop doing what you're doing!" which is similar to the "stop everything you're doing!" that CTRL+ALT+DEL tends to mean.

Matthew Haugen
  • 12,916
  • 5
  • 38
  • 54
  • 1
    +1 Your comment about the security reminded me of [this question](http://security.stackexchange.com/questions/34972/ctrlaltdel-login-rationale-behind-it) from the security stack exchange ("The operating system enforces a strong non-interception policy for this key combination") – Sayse Jul 22 '14 at 06:31
  • My application is going to be a Login point of the system. Once the user log in it will minimize and the user can do all the things. But to ensure that the user is log in through my application i want to do this – backtrack Jul 22 '14 at 06:34
  • So you're looking to overwrite the Windows login infrastructure? The best solution I have to that is that you write your own operating system. You could register your app in the task scheduler, I believe, to run on unlock (I know you can on login, but I'm not sure on unlock), but that's the closest you'll get. No matter what, even if you get those keys working, you'll never get into the actual dialog, where it asks you if you want to lock the computer. And you'd need to override that as well. And any `shutdown` commands that request a logout. And the Start menu. And the boot-up. – Matthew Haugen Jul 22 '14 at 06:39
  • 1
    I mean don't get me wrong, @Backtrack, there are cool things one might be able to do here. My point is just that Windows won't let you overrun its built-in security, especially the very measures it has put in place to avoid people overrunning its built in security. Regardless of how ethical and cool your solution is, if you can do it, other, less ethical people could too. And that would be bad for you, me, Microsoft, and pretty well every person in the world whose personal data lies directly or indirectly on machines powered and secured by the Windows and Active Directly architecture. – Matthew Haugen Jul 22 '14 at 06:41