views:

336

answers:

2

I need to initialize a variable when the user presses Ctrl-Alt-Del. Because this key combination is treated differently than others, the Windows Security Dialog Box appears immediately after it is pressed and my program can not detect whether it is pressed. I tried adding the code below to the KeyDown event, but it does not work.

     if ( (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Alt)) && Keyboard.IsKeyDown(Key.Delete))
     {
         // Initialize a variable
     }

If it is possible, how can I detect this key combination before the OS detects it? If not, how can I detect it after the OS?

+3  A: 

In short, you can't.

Josh Einstein
That talks about handling the shortcut before the OS handles it - what about detecting it happened after the fact?
280Z28
Perhaps you could make some assumptions by watching for various system events related to the interactive desktop (I imagine there's some kind of system event that says the logged on desktop is "locked") but as far as getting a notification about that particular key sequence, no it's intentionally unavailable to user-mode applications.
Josh Einstein
I just checked to see if SystemEvents.SessionSwitch event was raised when pressing CTL+ALT+DEL in Windows 7 and it is not raised. You may find something in the WTSRegisterSessionNotification API but I'm not sure.
Josh Einstein
This answer is plainly incorrect since VmWare does exactly this. When you press CTRL-ALT-DEL, it can't stop that info from being delivered to the host but it *does* also get it in the guest. VmWare suggest CTRL-ALT-INS in preference but it still does get the DEL version.
paxdiablo
It is my understanding that applications would never see the combination, but I am not willing to bet my house on it. I won't pretend to understand the depth of integration VMware has with the host but it certainly has much tighter hooks with the OS than a typical application especially with VT enabled in BIOS. I suppose you could try a low-level keyboard hook (WH_KEYBOARD_LL) but I'm certain you can't intercept it before Windows does.
Josh Einstein
A: 

Even if you can, you should not, as changing the meaning of Ctrl-Alt-Del would confuse users.

I hope it is not possible to-do without replacing keyboard drivers etc, as otherwise an application could make it impossible for the user to get to the task manager to kill the application.

Ian Ringrose
Ian, I do not intend to change the meaning of Ctrl-Alt-Del. All I want is to initialize a varible I have either before or after it is pressed.