home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / pascal / 7454 < prev    next >
Encoding:
Text File  |  1992-12-14  |  3.2 KB  |  96 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!das.wang.com!wang!news
  3. From: dov@menora.weizmann.ac.il (Dov Grobgeld)
  4. Subject: Trapping Ctrl-Alt-Del in a Turbo Pascal program
  5. Organization: The Weizmann Institute of Science
  6. Date: Sun, 13 Dec 1992 10:20:44 GMT
  7. Message-ID: <9212130826.AA14016@menora.weizmann.ac.il>
  8. Sender: news@wang.com
  9. Lines: 85
  10.  
  11. Here is my solution to the problem of trapping Ctrl-Alt-Del. As extra suger, 
  12. I'm providing hooks to make this program TSR. Happy hacking!
  13.  
  14. <<File: trapboot.pas>>
  15.  
  16. {$m 1024,0,0} { Necesarry if you want to make the program resident. }
  17. {****************************************************************************}
  18. {* NoBoot                                                                   *}
  19. {*                                                                          *}
  20. {* This program stops rebooting while it is running by trapping             *}
  21. {* Ctrl-Alt-Del.                                                            *}
  22. {*                                                                          *}
  23. {* Dov Grobgeld                                                             *}
  24. {* 1992-12-13                                                               *}
  25. {----------------------------------------------------------------------------}
  26.  
  27. USES
  28.   Dos, crt;
  29.  
  30. VAR
  31.   OldKBVec : POINTER;
  32.  
  33. { Declare all variables in our interrupt routine global so that no stack }
  34. { allocation of variables will be done during the interrupt.             }
  35. var
  36.   Regs : registers;
  37.   temp : byte;
  38.   KBflag1: BYTE ABSOLUTE $40:$17;
  39.  
  40. PROCEDURE MyKB; INTERRUPT;
  41. CONST
  42.   EOI = $20;
  43.   KB_DATA = $60;
  44.   KB_CTL = $61;
  45.   INT_CTL = $20;
  46.   DEL_sc = $53;   { Scancode of the del key }
  47.  
  48. BEGIN
  49.   { Check if Alt and Ctrl are pressed }
  50.   IF ((KBFlag1 AND 4)=4) AND ((KBFlag1 and 8)=8) AND
  51.     (Port[KB_DATA]= DEL_sc) THEN BEGIN { get scancode of pressed key }
  52.  
  53.     { The following four lines signals that the key is read and that the }
  54.     { hardware interrupt is over. }
  55.     temp:=Port[Kb_CTL];
  56.     Port[KB_CTL]:= temp OR $80;
  57.     Port[KB_CTL]:= temp;
  58.     Port[INT_CTL]:= EOI;
  59.  
  60.     { Don't do ANYTHING here that requires BIOS. This 'writeln' is using the }
  61.     { crt unit.                                                              }
  62.     writeln('Ouch! That hurts!');  { Show we are here and alive! }
  63.   END
  64.   ELSE BEGIN
  65.     intr($69, Regs); { Call the old interrupt routine }
  66.   END;
  67. END;
  68.  
  69. VAR
  70.   Ch : CHAR;
  71.  
  72. BEGIN
  73.   GetIntVec($9, OldKBVec);
  74.   SetIntVec($69, OldKBVec);
  75.   SetIntVec($9, @MyKB);
  76.  
  77.   { Keep(0); } { Uncomment and erase the rest of the lines to make this program resident. }
  78.  
  79.   REPEAT
  80.     writeln('Press escape to exit. Or Ctrl-Alt-Del if you want...');
  81.     ch:= readkey;
  82.   UNTIL ch=#27;
  83.  
  84.   { Forgetting the next line will very surely crash your computer. }
  85.   SetIntVec($9, OldKbVec);
  86. END.
  87.  
  88. --
  89.                                                         ___   ___
  90.                                                       /  o  \   o \
  91. Dov Grobgeld                                         ( o  o  ) o   |
  92. The Weizmann Institute of Science, Israel             \  o  /o  o /
  93. "Where the tree of wisdom carries oranges"              | |   | |
  94.                                                        _| |_ _| |_
  95.                                        
  96.