Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Code Snippet - Disable Reboot
Author:WebMaster
Category:Win32API
File Size:~ 1.81 KB
Uploaded at:15-Dec-02 04:14:09 pm
Description:
  Don't let the user reboot! Thanks goes to dLightSeeker@hotmail.com for the code snippet.
  
// Use a local keyboard hook to trap ctrl+alt+del keys.

#define _WIN32_WINNT 0x0400
#include <Windows.h>
#include<conio.h>
#include<stdio.h>
#include <stdlib.h>
#include <string.h>


///////////////////////////////////////////////////////////////////////////////


LRESULT CALLBACK LowLevelKeyboardProc(int nCode, 
   WPARAM wParam, LPARAM lParam) {

   BOOL fEatKeystroke = FALSE;
   if (nCode == HC_ACTION) {
      switch (wParam) {
      case WM_KEYDOWN:  case WM_SYSKEYDOWN:
      case WM_KEYUP:    case WM_SYSKEYUP: 
         PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) lParam;
         fEatKeystroke = 
            ( (p->vkCode == VK_TAB) && ((p->flags & LLKHF_ALTDOWN) != 0) ) ||
            ( (p->vkCode == VK_ESCAPE) && ((p->flags & LLKHF_ALTDOWN) != 0) ) ||
            ( (p->vkCode == VK_ESCAPE) && ((GetKeyState(VK_CONTROL) & 0x8000) != 0) )||
            ( (p->vkCode == 46) && ( (p->flags & LLKHF_ALTDOWN) != 0 ) && 
( (GetKeyState(VK_CONTROL) & 0x8000) != 0));   
    //its possible to add other keys....
    //the 46 means del
     break;
      }
   }
   return(fEatKeystroke ? 1 : CallNextHookEx(NULL, nCode, wParam, lParam));
}


///////////////////////////////////////////////////////////////////////////////


int WINAPI WinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) {

   // Install the low-level keyboard & mouse hooks
   HHOOK hhkLowLevelKybd  = SetWindowsHookEx(WH_KEYBOARD_LL, 
      LowLevelKeyboardProc, hinstExe, 0);

   // Keep this app running until we're told to stop
   MessageBox(NULL, 
      TEXT("Alt+Esc, Ctrl+Esc, and Alt+Tab are now not working.\n"),
      TEXT("Disable Low-Level Keys"), MB_OK);
   UnhookWindowsHookEx(hhkLowLevelKybd);

   return(0);
}


///////////////////////////////// End Of File /////////////////////////////////
User Contributed Comments(None)
NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[117058]
2D Rotated Rectangles Collision Detection[88983]
Keyboard Hook[77323]
UDP[65877]
HTTP Proxy[41214]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11561]
PS2 Mouse Driver[6958]
Wave Format Player[5792]
Reading FAT12[5620]
CodeGuru[5359]


All rights reserved to RageStorm © 2009