Solved

Trapping Ctrl-Alt-Delete...Possible?

Posted on 1998-05-14
10
340 Views
Last Modified: 2008-02-01
Is there anyway to trap Ctrl-Alt-Del?
0
Comment
Question by:GreatOne
  • 5
  • 5
10 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 30 total points
ID: 1250743
You must install system keyboard hook with SetWindowsHookEx with WH_KEYBOARD flag

0
 

Author Comment

by:GreatOne
ID: 1250744
That's great. But how exactly would I do that? can you give me the code to do it?

0
 
LVL 7

Expert Comment

by:galkin
ID: 1250745
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
 

Author Comment

by:GreatOne
ID: 1250746
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
 
LVL 7

Expert Comment

by:galkin
ID: 1250747
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:GreatOne
ID: 1250748
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
 
LVL 7

Expert Comment

by:galkin
ID: 1250749
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
 

Author Comment

by:GreatOne
ID: 1250750
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
 
LVL 7

Expert Comment

by:galkin
ID: 1250751
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
 

Author Comment

by:GreatOne
ID: 1250752
Thanks alot. you have been more than helpful. Really appreciate it. Here are your points. You earned it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
memory leak detection 9 71
Where is my core dump file in Ubuntu? 12 442
how to understand recursion 12 218
What is sub-make ? 2 39
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now