home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / itcmar90.arj / NORB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-07  |  1.9 KB  |  65 lines

  1. /************************************************
  2. * norb.c - Prevent Control-Alt-Delete reboots    *
  3. *                                                *
  4. * 891105 MCMason - originally coded                *
  5. ************************************************/
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <dos.h>
  10. #include <conio.h>
  11. #include <signal.h>
  12.  
  13. #define TRUE (1==1)                /* BOOLEAN TRUE    */
  14. #define ksDELCODE 0x53            /* DEL scan code*/
  15. static char far *_RB_keystat;    /*Kbd status ptr*/
  16.  
  17. /* Storage for old keyboard interrupt handler */
  18. static void (interrupt far *OldInt09H)(void);
  19.  
  20. /************************************************
  21. * RBinstall - install new kbd handler, install    *
  22. * func RBremove in ^Break handler.                *
  23. *                                                *
  24. * OUT: _RB_keystat - points to kbd status byte    *
  25. *       OldInt09H - points to old kbd intr hdlr    *
  26. ************************************************/
  27. void RBinstall(void)
  28.     {
  29.     OldInt09H = getvect(0x09);    /* Get old hdlr */
  30.     setvect(0x09,NewInt09H);    /* Put new hdlr    */
  31.     signal(SIGINT,RBremove);    /* Trap ^Break    */
  32.     /* point to keyboard status byte */
  33.     _RB_keystat = (char far *)0x00400017;
  34.     }
  35.  
  36. /************************************************
  37. * RBremove - remove new kbd handler                *
  38. ************************************************/
  39. void RBremove(void)
  40.     {
  41.     puts("Program terminated...");
  42.     setvect(0x09,OldInt09H);
  43.     exit(TRUE);
  44.     }
  45.  
  46. /************************************************
  47. *   NewInt09H - New keyboard interrupt handler.    *
  48. *    Detect (and prevent) Ctrl-Alt-Del reboots    *
  49. ************************************************/
  50. void interrupt far NewInt09H(void)
  51.     {
  52.     int i,j;
  53.     i=inp(0x60);            /* Get scan code    */
  54.     if (((i&0x7f)==ksDELCODE) &&      /*DELete?    */
  55.         ((*_RB_keystat&0x0c)==0x0c))  /*CTL+ALT?*/
  56.         {
  57.         j = inp(0x61);        /* Save kbd status    */
  58.         outp(0x61,j|0x80);    /* Reset kbd intrpt    */
  59.         outp(0x61,j&0x7f);
  60.         outp(0x20,0x20);
  61.         }
  62.     else
  63.         (*OldInt09H)();        /* Process key        */
  64.     }
  65.