Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

Trapping Ctrl-Alt-Delete...Possible?

Is there anyway to trap Ctrl-Alt-Del?
0
GreatOne
Asked:
GreatOne
  • 5
  • 5
1 Solution
 
galkinCommented:
You must install system keyboard hook with SetWindowsHookEx with WH_KEYBOARD flag

0
 
GreatOneAuthor Commented:
That's great. But how exactly would I do that? can you give me the code to do it?

0
 
galkinCommented:
HHOOK hHook;

LRESULT CALLBACK KeyboardProc(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
)
{
//check if these keys are pressed with GetKeyState and do //whatever you want

// otherwise call default processing
return ::CallNextHookEx(hHook, code, wParam, lParam);
}
 
hHook = ::SetWindowHookEx(WH_KEYBOARD, KeyboardProc, g_hInstance, 0);

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
GreatOneAuthor Commented:
Code looks good. two more quick questions. First, how would i call it? second, is this written in C++? only because I see ::'s everywhere and that reminds me of c++.
0
 
galkinCommented:
This is pure C code. Remove :: from the code. I don't undestand your first question. When you need to trap ctrl+alt+Del call SetWindowHookEx. from this moment your KeyboardProc which is global function wil be called to any keyboard event.
0
 
GreatOneAuthor Commented:
So if I want it to trap ctrl-alt-del, all i would have to do is paste that code into my code, and then in main put:
HHook hHook;
hHook =SetWindowHookEx(WH_KEYBOARD, KeyboardProc, g_hInstance, 0);

is that correct? do i need to include any special library? and am i correct in assuming nothing will happen when ctrl-alt-del is pressed and that the program will continue running?
0
 
galkinCommented:
Yes you can cut and paste my code application. You also need to add a little bit piece of code into KeyboardProc to designate when user has pressed these tree keys. As I mentioned use GetKeyState. Also do not remember unhook your hook when you are done with hooking. Use UnhookWindowsHookEx passing hook handle.
Also last point. Hook procedure(KeyboardProc) must be located into DLL.

0
 
GreatOneAuthor Commented:
Last little question: how do i get Hook procedure(KeyboardProc) into a DLL? And how do i unhook? what parameter should UnhookWindowsHookEx get? (could you show me an example)
I really appreciate all your help. You will get your points real soon.
0
 
galkinCommented:
Create DLL and place KeyboardProc there. Use LoadLibrary to load DLL and GetProcAddress to get pointer to KeyboardProc hook procedure. When DLL is unloaded call UnhookWindowsHookEx passing hHook you get from call to SetwindowsHookEx. For more information see http://www.codeguru.com/misc/hooks.shtml and http://www.codeguru.com/samples/mfc_hooks.shtml
0
 
GreatOneAuthor Commented:
Thanks alot. you have been more than helpful. Really appreciate it. Here are your points. You earned it.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now