如何禁止Ctrl和Alt之间的Win键?必须用HOOK: deactivate the (Windows) keys with a systemwide Hook? { ** What is a Hook? ** A hook is a point in the system message-handling mechanism where an application can install a subroutine to monitor the message traffic in the system and process certain types of messages before they reach the target window procedure. To use the Windows hook mechanism, a program calls the SetWindowsHookEx() API function, passing the address of a hook procedure that is notified when the specified event takes place. SetWindowsHookEx() returns the address of the previously installed hook procedure for the same event type. This address is important, because hook procedures of the same type form a kind of chain. Windows notifies the first procedure in the chain when an event occurs, and each procedure is responsible for passing along the notification. To do so, a hook procedure must call the CallNextHookEx() API function, passing the previous hook procedure's address. --> All system hooks must be located in a dynamic link library. ** The type of Hook used in this Example Code: ** The WH_GETMESSAGE hook enables an application to monitor/intercept messages about to be returned by the GetMessage or PeekMessage function. } { ** Hook Dll - WINHOOK.dll ** WINHOOK.dpr |-----WHookInt.pas ** Interface unit ** WHookDef.dpr } {********** Begin WHookDef.dpr **************} { Interface unit for use with WINHOOK.DLL } unit WHookDef; interface uses Windows; function SetHook(WinHandle: HWND; MsgToSend: Integer): Boolean; stdcall; function FreeHook: Boolean; stdcall; implementation function SetHook; external 'WINHOOK.DLL' Index 1; function FreeHook; external 'WINHOOK.DLL' Index 2; end. {********** End WHookDef.dpr **************} {********** Begin Winhook.dpr **************} { The project file } { WINHOOK.dll } library Winhook; uses WHookInt in 'Whookint.pas'; exports SetHook index 1, FreeHook index 2; end. {********** End Winhook.dpr **************} {********** Begin WHookInt.pas **************} unit WHookInt; interface uses Windows, Messages, SysUtils; function SetHook(WinHandle: HWND; MsgToSend: Integer): Boolean; stdcall; export; function FreeHook: Boolean; stdcall; export; function MsgFilterFunc(Code: Integer; wParam, lParam: Longint): Longint stdcall; export; implementation // Memory map file stuff { The CreateFileMapping function creates unnamed file-mapping object for the specified file. } function CreateMMF(Name: string; Size: Integer): THandle; begin Result := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, Size, PChar(Name)); if Result <> 0 then begin if GetLastError = ERROR_ALREADY_EXISTS then begin CloseHandle(Result); Result := 0; end; end; end; { The OpenFileMapping function opens a named file-mapping object. } function OpenMMF(Name: string): THandle; begin Result := OpenFileMapping(FILE_MAP_ALL_ACCESS, False, PChar(Name)); // The return value is an open handle to the specified file-mapping object. end; { The MapViewOfFile function maps a view of a file into the address space of the calling process. } function MapMMF(MMFHandle: THandle): Pointer; begin Result := MapViewOfFile(MMFHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0); end; { The UnmapViewOfFile function unmaps a mapped view of a file from the calling process's address space. } function UnMapMMF(P: Pointer): Boolean; begin Result := UnmapViewOfFile(P); end; function CloseMMF(MMFHandle: THandle): Boolean; begin Result := CloseHandle(MMFHandle); end; // Actual hook stuff type TPMsg = ^TMsg; const VK_D = $44; VK_E = $45; VK_F = $46; VK_M = $4D; VK_R = $52; MMFName = 'MsgFilterHookDemo'; type PMMFData = ^TMMFData; TMMFData = record NextHook: HHOOK; WinHandle: HWND; MsgToSend: Integer; end; // global variables, only valid in the process which installs the hook. var MMFHandle: THandle; MMFData: PMMFData;
function UnMapAndCloseMMF: Boolean; begin Result := False; if UnMapMMF(MMFData) then begin MMFData := nil; if CloseMMF(MMFHandle) then begin MMFHandle := 0; Result := True; end; end; end; { The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain. WH_GETMESSAGE Installs a hook procedure that monitors messages posted to a message queue. For more information, see the GetMsgProc hook procedure. } function SetHook(WinHandle: HWND; MsgToSend: Integer): Boolean; stdcall; begin Result := False; if (MMFData = nil) and (MMFHandle = 0) then begin MMFHandle := CreateMMF(MMFName, SizeOf(TMMFData)); if MMFHandle <> 0 then begin MMFData := MapMMF(MMFHandle); if MMFData <> nil then begin MMFData.WinHandle := WinHandle; MMFData.MsgToSend := MsgToSend; MMFData.NextHook := SetWindowsHookEx(WH_GETMESSAGE, MsgFilterFunc, HInstance, 0); if MMFData.NextHook = 0 then UnMapAndCloseMMF else Result := True; end else begin CloseMMF(MMFHandle); MMFHandle := 0; end; end; end; end; { The UnhookWindowsHookEx function removes the hook procedure installed in a hook chain by the SetWindowsHookEx function. } function FreeHook: Boolean; stdcall; begin Result := False; if (MMFData <> nil) and (MMFHandle <> 0) then if UnHookWindowsHookEx(MMFData^.NextHook) then Result := UnMapAndCloseMMF; end; (* GetMsgProc( nCode: Integer; {the hook code} wParam: WPARAM; {message removal flag} lParam: LPARAM {a pointer to a TMsg structure} ): LRESULT; {this function should always return zero} { See help on ==> GetMsgProc} *) function MsgFilterFunc(Code: Integer; wParam, lParam: Longint): Longint; var MMFHandle: THandle; MMFData: PMMFData; Kill: boolean; begin Result := 0; MMFHandle := OpenMMF(MMFName); if MMFHandle <> 0 then begin MMFData := MapMMF(MMFHandle); if MMFData <> nil then begin if (Code < 0) or (wParam = PM_NOREMOVE) then { The CallNextHookEx function passes the hook information to the next hook procedure in the current hook chain. } Result := CallNextHookEx(MMFData.NextHook, Code, wParam, lParam) else begin Kill := False; { Examples } with TMsg(Pointer(lParam)^) do begin // Kill Numbers if (wParam >= 48) and (wParam <= 57) then Kill := True; // Kill Tabulator if (wParam = VK_TAB) then Kill := True; end; { Example to disable all the start-Key combinations } case TPMsg(lParam)^.message of WM_SYSCOMMAND: // The Win Start Key (or Ctrl+ESC) if TPMsg(lParam)^.wParam = SC_TASKLIST then Kill := True; WM_HOTKEY: case ((TPMsg(lParam)^.lParam and $00FF0000) shr 16) of VK_D, // Win+D ==> Desktop VK_E, // Win+E ==> Explorer VK_F, // Win+F+(Ctrl) ==> Find:All (and Find: Computer) VK_M, // Win+M ==> Minimize all VK_R, // Win+R ==> Run program. VK_F1, // Win+F1 ==> Windows Help VK_PAUSE: // Win+Pause ==> Windows system properties Kill := True; end; end; if Kill then TPMsg(lParam)^.message := WM_NULL; Result := CallNextHookEx(MMFData.NextHook, Code, wParam, lParam) end; UnMapMMF(MMFData); end; CloseMMF(MMFHandle); end; end; initialization begin MMFHandle := 0; MMFData := nil; end; finalization FreeHook; end. {********** End WHookInt.pas **************} { *******************************************} { ***************** Demo ******************} { *******************************************} { ** HostApp.Exe ** HostApp.dpr |-----FrmMainU.pas } {********** Begin HostApp.dpr **************} { Project file } program HostApp; uses Forms, FrmMainU in 'FrmMainU.pas' {FrmMain}; {$R *.RES} begin Application.Initialize; Application.CreateForm(TFrmMain, FrmMain); Application.Run; end. {********** End HostApp.dpr **************} {********** Begin FrmMainU.pas **************} unit FrmMainU; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; const HookDemo = 'WINHOOK.dll'; const WM_HOOKCREATE = WM_USER + 300; type TFrmMain = class(TForm) Panel1: TPanel; BtnSetHook: TButton; BtnClearHook: TButton; procedure BtnSetHookClick(Sender: TObject); procedure BtnClearHookClick(Sender: TObject); procedure FormCreate(Sender: TObject); private FHookSet: Boolean; procedure EnableButtons; public end; var FrmMain: TFrmMain; function SetHook(WinHandle: HWND; MsgToSend: Integer): Boolean; stdcall; external HookDemo; function FreeHook: Boolean; stdcall; external HookDemo; implementation {$R *.DFM} procedure TFrmMain.EnableButtons; begin BtnSetHook.Enabled := not FHookSet; BtnClearHook.Enabled := FHookSet; end; // Start the Hook procedure TFrmMain.BtnSetHookClick(Sender: TObject); begin FHookSet := LongBool(SetHook(Handle, WM_HOOKCREATE)); EnableButtons; end; // Stop the Hook procedure TFrmMain.BtnClearHookClick(Sender: TObject); begin FHookSet := FreeHook; EnableButtons; BtnClearHook.Enabled := False; end; procedure TFrmMain.FormCreate(Sender: TObject); begin EnableButtons; end; end. {********** End FrmMainU.pas **************}
1.屏蔽 ASM IN AL,21H OR AL,02H OUT 21H,AL END; 2.解锁 ASM IN AL,21H AND AL,0F0H OUT 21H,AL END;
Key = #0
分类:系统相关 ( 版主:luyear, zyy04 )
来自:xan, 时间:2001-8-26 21:09:00, ID:607224 [显示:小字体 | 大字体]
rt!
来自:lsyx, 时间:2001-9-5 14:20:00, ID:612055
win2000系统不允许屏蔽系统建,因为它的登录和任务管理都用的是ctrl+alt+del
来自:goddy, 时间:2001-9-5 18:39:00, ID:612514
hook the key
来自:梆梆, 时间:2001-9-6 16:15:00, ID:613742
有人认为使用一个键盘钩子WH_KEYBOARD就可以解决问题,但实际上问题并不是那么简单。
这是因为键盘钩子WH_KEYBOARD不能截取到系统键的输入。在Windows NT 4.0 SP3或 Windows 2000下系统提供了一个底层系统钩子(Low Level Hook)WH_KEYBOARD_LL。底层键盘钩子存在于用户敲击键盘和系统处理之间,而普通键盘钩子则存在于系统产生WM_KEY***消息之后。很清楚,普通键盘钩子只能截获WM_KEY***消息,而不能对系统键进行操作。但是底层键盘钩子有一个致命的弱点,就是如果调用它的进程或线程出现死循环,则系统将不能处理任何键盘操作。为了解决这个问题,微软在注册表中给出了一个底层键盘钩子处理的限制时间,如果超出了这个时间,系统将进入正常处理。这个时间键值存储在注册表的HKEY_CURRENT_USER\Control Panel\Desktop\ LowLevelHooksTimeout下。
首先需要安装钩子:
HHOOK SetWindowsHookEx(int iHookCode,
HOOKPROC lpfn,HINSTANCE hModule,DWORD dwThreadId);
其中,第一个参数是钩子的类型;第二个参数是钩子函数的地址;第三个参数是包含钩子函数的模块句柄;第四个参数指定监视的线程。如果指定确定的线程,即为线程专用钩子;如果指定为空,即为全局钩子。其中,全局钩子函数必须包含在DLL(动态链接库)中,而线程专用钩子还可以包含在可执行文件中。得到控制权的钩子函数在完成对消息的处理后,如果想要该消息继续传递,那么它必须调用另外一个SDK中的API函数CallNextHookEx来传递它。钩子函数也可以通过直接返回TRUE来丢弃该消息,并阻止该消息的进一步传递。
下面是实现底层键盘钩子的部分源代码:
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));
break;
}
}
return(fEatKeystroke ? 1 : CallNextHookEx(NULL, nCode, wParam, lParam));
}
int WINAPI WinMain(HINSTANCE hinstExe, HIN
STANCE, PTSTR pszCmdLine, int)
{
//安装底层键盘钩子
HHOOK hhkLowLevelKybd = SetWindow
sHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc,
hinstExe, 0);
MessageBox(NULL,TEXT(“Alt+Esc, Ctrl+Esc, and Alt+Tab are now disabled.\n”),TEXT(“Click \“Ok\” to terminate this application and re-enable these keys.”),TEXT(“Disable Low-Level Keys”), MB_OK);
UnhookWindowsHookEx(hhkLowLevelKybd);
return(0);
}
来自:xWolf, 时间:2001-9-6 17:36:00, ID:613901
上面的例子是MSDN里的,不过很显然,是无法屏蔽Ctrl+Alt+Del的。我只知道如何去模拟一次Ctrl+Alt+Del
来自:smilboy, 时间:2001-9-9 0:21:00, ID:617046
能不能用汇编完全锁死键盘呢?
请讨论:给出汇编代码,成功后我给200分
来自:forss, 时间:2001-9-13 13:16:00, ID:623708
用汇编锁键盘很简单,
procedure Tmainform.Lockkey(lock: boolean);
begin
if lock = true then
begin
asm //封锁20端口 锁定键盘 98&95
IN AL,21H
OR AL,02H
OUT 21H,AL
end;
end
else
begin
asm //解锁20端口 解锁键盘
IN AL,21H
AND AL,0FDH
OUT 21H,AL
end;
end;
end;
来自:iamfly, 时间:2001-9-13 13:22:00, ID:623725
这段汇编在2000下能用吗?我怀疑:)
来自:forss, 时间:2001-9-13 13:29:00, ID:623735
当然不行,,写的很清楚啦:)
来自:iamfly, 时间:2001-9-13 13:36:00, ID:623750
既然不行,在98下不用汇编也能做到吗:)
现在XAN就是想知道在2000下怎么做^_^
我也曾经尝试过,最后就是没下文
来自:atorm, 时间:2001-9-20 19:41:00, ID:636154
1、运行注册表编辑器。
2、打开HKEY_CURRENT_USER\Software\Microsoft\windows\CurrentVersion\Policies\Explorer子键,
新建一个名为NoWinKeys的双字节值,数值为1。
来自:guoyan, 时间:2001-9-22 10:47:00, ID:639083
to atorm :
您的方法管用吗?
来自:softdog, 时间:2001-9-22 11:08:00, ID:639101
2000下允许截获CTRL+ALT+DEL组合吗?
来自:xan, 时间:2001-9-23 13:00:00, ID:640476
我的本意是不想让别人结束我的程序,如果能把进程隐藏掉也行,
比如我做一个收费系统的客户端.拜托各位给我想想办法.
来自:fanren945, 时间:2001-9-23 13:18:00, ID:640489
[:)][center][/center]关注
来自:mikedeakins, 时间:2001-9-23 15:39:00, ID:640617
做成 windows service,你的收费系统总是要运行在 user 权限上吧?这个权限不能
进行服务管理。
如果你觉得麻烦,可以简化 service,判断你的程序被结束了就重新加载那个程序。
来自:xan, 时间:2001-9-28 9:47:00, ID:649203
我得意思是 在每台客户机上安装一客户端软件,每次开机,程序自动运行,连接到服
务器上,这样当然是不允许他关闭我得程序,目的能达到不能关闭就行,屏蔽系统键是一
个办法,隐藏进程好像是一个更好的办法。
如果不能屏蔽系统键,那么隐藏进程有没有好的方法呢?我知道在98下是可以的,调用一个
api函数即可,但2000下此函数不支持,不知道还有没有别的函数?请高手不吝赐教!!!
我见过一个程序,在任务管理器中根本看不到它,就是不知道他是怎么实现的!
来自:zeroworld, 时间:2001-9-28 10:32:00, ID:649284
不用想了,win2K下肯定是不能屏蔽Ctrl+alt+del的,这是为了2K的安全性考虑的
进程也是不能屏蔽掉的,只要是进程在win2K的任务管理器中都是能看到的
最好的方法是用线程,将dll的线程导入win2K常用的程序中,比如rundll32调用这个dll函数
这样在任务管理器中看到的就是rundll32这个进程了,一般人不会注意,当然这个只是简单的
隐藏,比较低级吧,高级一点的是用函数转发。将win2K常用的dll替换成你的。例如shell32.dll
等等的,将原来的shell32.dll改名为shell32x.dll等,然后判断win2K的请求
来自:smilboy, 时间:2001-9-28 11:53:00, ID:649488
如果是隐藏进程可以把你的程序绑定到Explorer.exe这样他就没办法关闭你的程序了
如何绑定?请查阅黑客网站或者这里
http://jingtao.delphibbs.com 他有一个二合一的工具,你还可以和他要该程序的Delphi的
原文件[:)]
来自:flier, 时间:2001-9-29 4:18:00, ID:650659
以上面这些方法在Win2K下根本不可能完全屏蔽Ctrl+Alt+Del,
因为这三个键以及其他几个热键的处理,是独立于键盘队列的
以我目前所知,唯一一种用户模式编程实现的可行方法就是
编写GINA DLL,至于怎么写,你如果自认为水平足够,直接去看MSDN
好了,如果没把握最好别自找麻烦,否则就要重装系统了 :)
来自:zw84611, 时间:2001-9-30 13:45:00, ID:652754
到www.vckbase.com去看看。
WINDOWS NT/2000下如何屏蔽CTRL+ALT+DEL
作者:ac952_z_cn
前言
在WINDOWS 9X环境中我们可以使用SystemParametersInfo (SPI_SCREENSAVERRUNNING, 1,NULL, 0);来屏蔽CTRL+ALT+DEL,但在NT/2000环境下却行不通,即使使用WH_KEYBOARD_LL这个低级的键盘hook也无法拦截!笔者通过替换GINA DLL的方式很好地实现了在NT/2000下屏蔽CTRL+ALT+DEL的功能。
下载源代码 6K
一、原理
在NT/2000中交互式的登陆支持是由WinLogon调用GINA DLL实现的,GINA DLL提供了一个交互式的界面为用户登陆提供认证请求。在WinLogon初始化时,就向系统注册截获CTRL+ALT+DEL消息,所以其他程序就无法得到CTRL+ALT+DEL的消息。
WinLogon会和GINA DLL进行交互,缺省是MSGINA.DLL(在System32目录下)。微软同时也为我们提供的接口,自己
可以编GINA DLL来代替MSGINA.DLL。
WinLogon初始化时会创建3个桌面:
(1)、winlogon桌面:主要显示window 安全等界面,如你按下CTRL+ALT+DEL,登陆的界面等
(2)、应用程序桌面:我们平时见到的那个有我的电脑的界面
(3)、屏幕保护桌面:屏幕保护显示界面。
在用户登陆以后,按下CTRL+ALT+DEL键的时候,WinLogon回调用GINA DLL的输出函数:WlxLoggedOnSAS,
这时正处于winlogon桌面,我们只要直接将他转向应用程序桌面,系统就不会显示Windows安全那个界面,换一种说法
也就是用户按下CTRL+ALT+DEL后,不会起什么作用。当是我们在切换桌面的时候会出现屏幕闪动!
二、程序实现
GINA DLL要输出下列函数(winlogon会调用)
WlxActivateUserShell
WlxDisplayLockedNotice
WlxDisplaySASNotice
WlxDisplayStatusMessage
WlxGetStatusMessage
WlxInitialize
WlxIsLockOk
WlxIsLogoffOk
WlxLoggedOnSAS
WlxLoggedOutSAS
WlxLogoff
WlxNegotiate
WlxNetwo
把zwjchina(蒲石)老兄发的收藏先!
只差屏蔽Window键了,我已经查了以前所有贴子,还是没有找到,难道CSDN真的没有高人了!
关注中...
deactivate the (Windows) keys with a systemwide Hook?
{
** What is a Hook? ** A hook is a point in the system message-handling mechanism where an
application can install a subroutine to monitor the message traffic in
the system and process certain types of messages before they reach the target window procedure. To use the Windows hook mechanism, a program calls the SetWindowsHookEx() API function,
passing the address of a hook procedure that is notified when the specified
event takes place. SetWindowsHookEx() returns the address of the previously installed
hook procedure for the same event type. This address is important,
because hook procedures of the same type form a kind of chain.
Windows notifies the first procedure in the chain when an event occurs,
and each procedure is responsible for passing along the notification.
To do so, a hook procedure must call the CallNextHookEx() API function,
passing the previous hook procedure's address. --> All system hooks must be located in a dynamic link library. ** The type of Hook used in this Example Code: ** The WH_GETMESSAGE hook enables an application to monitor/intercept messages
about to be returned by the GetMessage or PeekMessage function.
}
{ ** Hook Dll - WINHOOK.dll **
WINHOOK.dpr
|-----WHookInt.pas ** Interface unit ** WHookDef.dpr } {********** Begin WHookDef.dpr **************} { Interface unit for use with WINHOOK.DLL } unit WHookDef; interface uses
Windows; function SetHook(WinHandle: HWND; MsgToSend: Integer): Boolean; stdcall;
function FreeHook: Boolean; stdcall; implementation function SetHook; external 'WINHOOK.DLL' Index 1;
function FreeHook; external 'WINHOOK.DLL' Index 2; end. {********** End WHookDef.dpr **************}
{********** Begin Winhook.dpr **************} { The project file } { WINHOOK.dll }
library Winhook; uses
WHookInt in 'Whookint.pas'; exports
SetHook index 1,
FreeHook index 2;
end. {********** End Winhook.dpr **************}
{********** Begin WHookInt.pas **************} unit WHookInt; interface uses
Windows, Messages, SysUtils; function SetHook(WinHandle: HWND; MsgToSend: Integer): Boolean; stdcall; export;
function FreeHook: Boolean; stdcall; export;
function MsgFilterFunc(Code: Integer; wParam, lParam: Longint): Longint stdcall; export; implementation
// Memory map file stuff {
The CreateFileMapping function creates unnamed file-mapping object
for the specified file.
} function CreateMMF(Name: string; Size: Integer): THandle;
begin
Result := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, Size, PChar(Name));
if Result <> 0 then
begin
if GetLastError = ERROR_ALREADY_EXISTS then
begin
CloseHandle(Result);
Result := 0;
end;
end;
end; { The OpenFileMapping function opens a named file-mapping object. } function OpenMMF(Name: string): THandle;
begin
Result := OpenFileMapping(FILE_MAP_ALL_ACCESS, False, PChar(Name));
// The return value is an open handle to the specified file-mapping object.
end; {
The MapViewOfFile function maps a view of a file into
the address space of the calling process.
} function MapMMF(MMFHandle: THandle): Pointer;
begin
Result := MapViewOfFile(MMFHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
end; {
The UnmapViewOfFile function unmaps a mapped view of a file
from the calling process's address space.
} function UnMapMMF(P: Pointer): Boolean;
begin
Result := UnmapViewOfFile(P);
end; function CloseMMF(MMFHandle: THandle): Boolean;
begin
Result := CloseHandle(MMFHandle);
end;
// Actual hook stuff type
TPMsg = ^TMsg; const
VK_D = $44;
VK_E = $45;
VK_F = $46;
VK_M = $4D;
VK_R = $52; MMFName = 'MsgFilterHookDemo'; type
PMMFData = ^TMMFData;
TMMFData = record
NextHook: HHOOK;
WinHandle: HWND;
MsgToSend: Integer;
end; // global variables, only valid in the process which installs the hook.
var
MMFHandle: THandle;
MMFData: PMMFData;
begin
Result := False;
if UnMapMMF(MMFData) then
begin
MMFData := nil;
if CloseMMF(MMFHandle) then
begin
MMFHandle := 0;
Result := True;
end;
end;
end; {
The SetWindowsHookEx function installs an application-defined
hook procedure into a hook chain. WH_GETMESSAGE Installs a hook procedure that monitors messages
posted to a message queue.
For more information, see the GetMsgProc hook procedure.
} function SetHook(WinHandle: HWND; MsgToSend: Integer): Boolean; stdcall;
begin
Result := False;
if (MMFData = nil) and (MMFHandle = 0) then
begin
MMFHandle := CreateMMF(MMFName, SizeOf(TMMFData));
if MMFHandle <> 0 then
begin
MMFData := MapMMF(MMFHandle);
if MMFData <> nil then
begin
MMFData.WinHandle := WinHandle;
MMFData.MsgToSend := MsgToSend;
MMFData.NextHook := SetWindowsHookEx(WH_GETMESSAGE, MsgFilterFunc, HInstance, 0); if MMFData.NextHook = 0 then
UnMapAndCloseMMF
else
Result := True;
end
else
begin
CloseMMF(MMFHandle);
MMFHandle := 0;
end;
end;
end;
end;
{
The UnhookWindowsHookEx function removes the hook procedure installed
in a hook chain by the SetWindowsHookEx function.
} function FreeHook: Boolean; stdcall;
begin
Result := False;
if (MMFData <> nil) and (MMFHandle <> 0) then
if UnHookWindowsHookEx(MMFData^.NextHook) then
Result := UnMapAndCloseMMF;
end; (*
GetMsgProc(
nCode: Integer; {the hook code}
wParam: WPARAM; {message removal flag}
lParam: LPARAM {a pointer to a TMsg structure}
): LRESULT; {this function should always return zero} { See help on ==> GetMsgProc}
*) function MsgFilterFunc(Code: Integer; wParam, lParam: Longint): Longint;
var
MMFHandle: THandle;
MMFData: PMMFData;
Kill: boolean;
begin
Result := 0;
MMFHandle := OpenMMF(MMFName);
if MMFHandle <> 0 then
begin
MMFData := MapMMF(MMFHandle);
if MMFData <> nil then
begin
if (Code < 0) or (wParam = PM_NOREMOVE) then
{
The CallNextHookEx function passes the hook information to the
next hook procedure in the current hook chain.
}
Result := CallNextHookEx(MMFData.NextHook, Code, wParam, lParam)
else
begin
Kill := False; { Examples }
with TMsg(Pointer(lParam)^) do
begin
// Kill Numbers
if (wParam >= 48) and (wParam <= 57) then Kill := True;
// Kill Tabulator
if (wParam = VK_TAB) then Kill := True;
end; { Example to disable all the start-Key combinations }
case TPMsg(lParam)^.message of
WM_SYSCOMMAND: // The Win Start Key (or Ctrl+ESC)
if TPMsg(lParam)^.wParam = SC_TASKLIST then Kill := True; WM_HOTKEY:
case ((TPMsg(lParam)^.lParam and $00FF0000) shr 16) of
VK_D, // Win+D ==> Desktop
VK_E, // Win+E ==> Explorer
VK_F, // Win+F+(Ctrl) ==> Find:All (and Find: Computer)
VK_M, // Win+M ==> Minimize all
VK_R, // Win+R ==> Run program.
VK_F1, // Win+F1 ==> Windows Help
VK_PAUSE: // Win+Pause ==> Windows system properties
Kill := True;
end;
end;
if Kill then TPMsg(lParam)^.message := WM_NULL;
Result := CallNextHookEx(MMFData.NextHook, Code, wParam, lParam)
end;
UnMapMMF(MMFData);
end;
CloseMMF(MMFHandle);
end;
end;
initialization
begin
MMFHandle := 0;
MMFData := nil;
end; finalization
FreeHook;
end. {********** End WHookInt.pas **************}
{ *******************************************}
{ ***************** Demo ******************}
{ *******************************************} { ** HostApp.Exe **
HostApp.dpr
|-----FrmMainU.pas } {********** Begin HostApp.dpr **************} { Project file } program HostApp; uses
Forms,
FrmMainU in 'FrmMainU.pas' {FrmMain}; {$R *.RES} begin
Application.Initialize;
Application.CreateForm(TFrmMain, FrmMain);
Application.Run;
end. {********** End HostApp.dpr **************}
{********** Begin FrmMainU.pas **************} unit FrmMainU; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls; const
HookDemo = 'WINHOOK.dll'; const
WM_HOOKCREATE = WM_USER + 300; type
TFrmMain = class(TForm)
Panel1: TPanel;
BtnSetHook: TButton;
BtnClearHook: TButton;
procedure BtnSetHookClick(Sender: TObject);
procedure BtnClearHookClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FHookSet: Boolean;
procedure EnableButtons;
public end; var
FrmMain: TFrmMain; function SetHook(WinHandle: HWND; MsgToSend: Integer): Boolean; stdcall;
external HookDemo; function FreeHook: Boolean; stdcall; external HookDemo; implementation {$R *.DFM} procedure TFrmMain.EnableButtons;
begin
BtnSetHook.Enabled := not FHookSet;
BtnClearHook.Enabled := FHookSet;
end; // Start the Hook
procedure TFrmMain.BtnSetHookClick(Sender: TObject);
begin
FHookSet := LongBool(SetHook(Handle, WM_HOOKCREATE));
EnableButtons;
end; // Stop the Hook
procedure TFrmMain.BtnClearHookClick(Sender: TObject);
begin
FHookSet := FreeHook;
EnableButtons;
BtnClearHook.Enabled := False;
end; procedure TFrmMain.FormCreate(Sender: TObject);
begin
EnableButtons;
end; end. {********** End FrmMainU.pas **************}
ASM
IN AL,21H
OR AL,02H
OUT 21H,AL
END;
2.解锁
ASM
IN AL,21H
AND AL,0F0H
OUT 21H,AL
END;
[email protected]