Halting Keypresses?

Hi all,
    I am writing a program that is supposed to lock a user from the common key presses, i.e. Alt + F4, Crtl+Alt+Del, etc.  I know I have to have
case WM_KEYDOWN:
    switch(wParam)
    {
    //The Keypresses
    }
    break;

My problem is that I do not know how to halt the keys from doing anything.  I am certain that VK_F4 is for the F4 key, but how do I link alll of the keypresses of one command together, i.e. the keypresses for the Task Manager.  I also need to know how to make the window, that will disappear, to keep windows from using these keypresses.  And last but not least, if anyone could tell me how to keep the window the focus the whole time it is shown.  For example, the window has a username and password screen, and I was wondering how am I to keep this window from disappearing pre-maturely.  I want it so the window goes away after the username and password have been verified.  Thank you in advanced.


C.Timko



Answer this question

Halting Keypresses?

  • sambar

  • pdq2

    I'll just repeat Martin's comment: the best and easiet way to do this is to use Group Polices: anything else is just re-inventing the wheel and is going to be error prone as these are not easy things to get right.

  • AGK

    First of all. Using a keyboard hook would be a good solution. Just search the MSDN for SetWindowsHookEx. You need a system wide hook.

    BUT!!! It is not possible to block Ctrl+Alt+Del, because this keyboard sequence is owned by the GINA.



  • Niranjan80

    I forgot that part of the list, my mistake.  The IT Director doesn't want to use the group policy.  Our system is 55% Macintosh computers and 5% Linux.  The question was only how do I impliment the usage of the KeyboardHook, and nothing more.  If you don't want to answer the  question thats fine, you don't have to tell me about group policies.  I am almost a MSCDT for the XP operating system, I only have to take the test.

    C.Timko


  • WendellB

    The problem with global (system wide) hooks is that the code must reside inside a DLL, the code itself (the DLL) is loaded into all processes when install the hook.
    This is also called injecting! If your hook is unstable, every windows program can fail, due to a simple hook.

    Read this about GINA:
    http://msdn.microsoft.com/library/en-us/secauthn/security/winlogon_and_gina.asp

    There is a sample code of a GINA replacement here:
    http://www.codeproject.com/useritems/GINA_SPY.asp

    But be careful. You might make your system unusable.

    My hint: Use Windows Policies to suppress the task manager. This is no problem at all. You do not need to code anything!

  • DawnJ

    Ok,
    I did the following:
    HHOOK hKeyboard;
    ...
    hKeyboard = SetWindowsHookEx(WH_KEYBOARD,0,NULL,0);
    ...
    UnhookWindowsHookEx(hKeyboard);
    ...//EOF

    I understand why, but I am coming across a dilema.  Where I put the first 0, it says in MSDN "Pointer to the hook procedure.  If the dwThreadId(the last 0) parameter is zero or specifies the identifier of a thread created by a different process,...,lpfn(my first 0) can point to a hook procedure in the code associated with the current process."  Could you make some sense out of this for me.  I am really confused.  I have read several c++ books and I now what pointers are and what hooks are, but I dont think it is very clear.  Also, what is GINA.  I can't block Crtl+Alt+Delete for security reasons. (The kids in our school use the taskmanager to close the Syncroneyes Program that watches over the computers.)  Is it just possible to block the taskmanager so it can't execute unless they are administrators   Thank you for your help so far.

    C.Timko


  • skeize

    Martin,
       I understand that you mean well, and I know that that will work, but let me explain myself some more.  The full description of what I am supposed to make:
    1) A program with a login screen for a students username and password.
    2) Program MUST disable the log-out window and the shutdown window.
    3) All system prefernces are to be disabled.
    4) All "harmful" keypresses disabled. (i.e. Crtl+Alt+Del, Alt+F4, Esc, etc)
    5) Disallowed access to the internet if they are not registered for it.
    6) Disallowed access to the C:\
    7) Records the amount of time a user is logged in.
    8) IF administrator logs in under their username, all of the above are released for their usage.
    9) If the program crashes the computer will auto restart.
    10) Checks username and pass with an ODBC db

    My high school has made this a learning time for me.  My deadline is on Nov 17.  Also our school is really behind in technology and is unable to issue groups via a server, because we only have 2 and the harddrives are really small.

    C.Timko

  • Miha Markic

    @Timko!
    Everything you want ist just a matter of group policies and rights in a domain!
    Except one: But why shouldn't say logout



  • Rohidas K

    Could you give me some examples of what you mean   Thanks for the GINA info.


  • Halting Keypresses?