在w2k下禁止ctrl+alt+del,alt+tab要示例,200大元!(200分)

  • 主题发起人 主题发起人 wlyft
  • 开始时间 开始时间
当你不需要让用户按Alt+Enter、Ctrl+Alt+Del、Ctrl+Esc等功能键的时候加入以下代码: <br>Var <br>temp:integer; <br>begin <br>SystemParametersInfo(Spi_screensaverrunning,1,@temp,0); <br>end; <br>当你要恢复功能键时用以下代码: <br>Var <br>Temp:integer; <br>begin <br>SystemParametersInfo(spi_screensaverrunning,0,@temp,0); <br>end; <br>
 
我试过在win9x是可以的,但在w2k是无效的!<br>要不然我也不会出200分出来!
 
要写驱动
 
在W2K下好象是没有什么办法可以屏蔽掉这几个键的,如果知道,也请通知我
 
SystemParametersInfo(Spi_screensaverrunning,1,@temp,0) 函数用于 Win9x/Me 中可以<br>是系统进入屏幕保护状态,达到屏蔽 Ctrl+Alt+Del 这样的特殊系统组合键,但是在 WinNT<br>/2000 下无效。在 NT 4.0 + SP3/Win 2000 环境下,需要用到低级键盘钩子,才能捕获到<br>这类按键。程序中需要用到 KBDLLHOOKSTRUCT 这个结构,但在 Delphi 中没有声明,还要<br>用到几个常量,Delphi 也没有声明,估计是被省略掉了。键盘钩子函数如果要变成全局钩<br>子,必须存放在 DLL 中;如果仅是对于特定线程有效,可以放在 EXE 中。下面是我的代码<br>例子,在 Delphi 6 中编译通过:<br><br>unit Main;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, ExtCtrls, StdCtrls;<br><br>type<br>&nbsp; TMainForm = class(TForm)<br>&nbsp; &nbsp; EnableBtn: TButton;<br>&nbsp; &nbsp; DisableBtn: TButton;<br>&nbsp; &nbsp; AboutBtn: TButton;<br>&nbsp; &nbsp; ExitBtn: TButton;<br>&nbsp; &nbsp; Bell1: TBevel;<br>&nbsp; &nbsp; Image: TImage;<br>&nbsp; &nbsp; procedure AboutBtnClick(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure EnableBtnClick(Sender: TObject);<br>&nbsp; &nbsp; procedure DisableBtnClick(Sender: TObject);<br>&nbsp; &nbsp; procedure ExitBtnClick(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; MainForm: TMainForm;<br><br>implementation<br><br>uses Hook;<br><br>{$R *.dfm}<br><br>type<br>&nbsp; // Declaration from VC++ WINUSER.H<br>&nbsp; //<br>&nbsp; PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;<br>&nbsp; KBDLLHOOKSTRUCT = record<br>&nbsp; &nbsp; vkCode: DWORD;<br>&nbsp; &nbsp; scanCode: DWORD;<br>&nbsp; &nbsp; flags: DWORD;<br>&nbsp; &nbsp; time: DWORD;<br>&nbsp; &nbsp; dwExtraInfo: DWORD;<br>&nbsp; end;<br><br>const<br>&nbsp; LLKHF_ALTDOWN &nbsp;= KF_ALTDOWN shr 8;<br>&nbsp; WH_KEYBOARD_LL = 13;<br><br>var<br>&nbsp; hhkNTKeyboard: HHOOK; // 钩子句柄<br><br>// 低级键盘钩子回调函数<br>//<br>function LowLevelKeyboardFunc(nCode: Integer; w_Param: WPARAM;<br>&nbsp; l_Param: LPARAM): LRESULT; stdcall;<br>var<br>&nbsp; blEatKeystroke: Boolean;<br>&nbsp; p: PKBDLLHOOKSTRUCT;<br>begin<br>&nbsp; blEatKeystroke := False;<br>&nbsp; if nCode = HC_ACTION then<br>&nbsp; begin<br>&nbsp; &nbsp; case w_Param of<br>&nbsp; &nbsp; &nbsp; WM_KEYDOWN,<br>&nbsp; &nbsp; &nbsp; WM_SYSKEYDOWN,<br>&nbsp; &nbsp; &nbsp; WM_KEYUP,<br>&nbsp; &nbsp; &nbsp; WM_SYSKEYUP:<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p := PKBDLLHOOKSTRUCT(l_Param);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 进行按键过滤<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blEatKeystroke := (((p^.vkCode = VK_TAB) and<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((p^.flags and LLKHF_ALTDOWN) &lt;&gt; 0)) or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((p^.vkCode = VK_ESCAPE) and<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((p^.flags and LLKHF_ALTDOWN) &lt;&gt; 0)) or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((p^.vkCode = VK_ESCAPE) and<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((GetKeyState(VK_CONTROL) and $8000) &lt;&gt; 0)) or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((p^.vkCode = VK_DELETE) and<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((p^.flags and LLKHF_ALTDOWN) &lt;&gt; 0) and<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((GetKeyState(VK_CONTROL) and $8000) &lt;&gt; 0)));<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end; // End of Case<br>&nbsp; end;<br>&nbsp; if blEatKeystroke then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := 1; &nbsp; &nbsp; &nbsp; // 捕获这些组合键,按键消息由自己处理,必须返回 1<br>&nbsp; &nbsp; Hook.ShowHookInfo; // 显示一个窗口,你可以改为自己的处理代码<br>&nbsp; end<br>&nbsp; else<br>&nbsp; &nbsp; // 其他的按键,交由别的线程处理(过滤)<br>&nbsp; &nbsp; Result := CallNextHookEx(0, nCode, w_Param, l_Param);<br>end;<br><br>procedure TMainForm.AboutBtnClick(Sender: TObject);<br>begin<br>&nbsp; Application.MessageBox(<br>&nbsp; &nbsp; PChar('Windows NT 键盘钩子演示程序'#13#10#13#10'作者:Phoenix2000,2001年7月。'),<br>&nbsp; &nbsp; '关于本程序', 0);<br>end;<br><br>procedure TMainForm.FormCreate(Sender: TObject);<br>begin<br>&nbsp; hhkNTKeyboard := 0; // 钩子句柄初值<br>end;<br><br>procedure TMainForm.EnableBtnClick(Sender: TObject);<br>begin<br>&nbsp; // 挂上键盘钩子<br>&nbsp; //<br>&nbsp; hhkNTKeyboard := SetWindowsHookEx(WH_KEYBOARD_LL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LowLevelKeyboardFunc,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HInstance, 0);<br>&nbsp; if hhkNTKeyboard &lt;&gt; 0 then<br>&nbsp; &nbsp; Application.MessageBox('系统键盘钩子已经启动了!', '信息', 64)<br>&nbsp; else<br>&nbsp; &nbsp; Application.MessageBox('无法启动系统键盘钩子!', '错误', 16);<br>end;<br><br>procedure TMainForm.DisableBtnClick(Sender: TObject);<br>begin<br>&nbsp; // 解除键盘钩子<br>&nbsp; //<br>&nbsp; if hhkNTKeyboard = 0 then<br>&nbsp; &nbsp; Application.MessageBox('系统键盘钩子已经被禁止了!', '警告', 48)<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; UnhookWindowsHookEx(hhkNTKeyboard); // 卸载钩子<br>&nbsp; &nbsp; hhkNTKeyboard := 0;<br>&nbsp; &nbsp; Hook.CleanHookForm; // 此行代码与钩子无关,不要误解,是我自己的窗体清除<br>&nbsp; &nbsp; Application.MessageBox('成功卸载系统键盘钩子!', '信息', 64)<br>&nbsp; end;<br>end;<br><br>procedure TMainForm.ExitBtnClick(Sender: TObject);<br>begin<br>&nbsp; Close;<br>end;<br><br>procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>begin<br>&nbsp; CanClose := (hhkNTKeyboard = 0);<br>&nbsp; if not CanClose then<br>&nbsp; &nbsp; Application.MessageBox('请先卸载系统键盘钩子,然后再退出本程序!', '警告', 48);<br>end;<br><br>procedure TMainForm.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; if hhkNTKeyboard &lt;&gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; UnhookWindowsHookEx(hhkNTKeyboard);<br>&nbsp; &nbsp; hhkNTKeyboard := 0;<br>&nbsp; end;<br>&nbsp; Hook.CleanHookForm;<br>end;<br><br>end.<br><br>以上的代码在 NT 4.0 + SP3/Win 2000 下能捕获 Alt + Tab、Alt + ESC、Ctrl + ESC 这<br>样的组合键,而 Ctrl + Alt + Del 无法捕获。有兴趣的朋友自己研究一下又没有别的办<br>法,或是我的代码由否不妥之处。另外,NT 环境下用低级键盘钩子,只有在 NT 4.0 + SP3<br>以上的版本才有效,在 NT 4 + SP2 都是无效的。在 Win2000 下当然有效了。<br>
 
用Hook LowLevelKeyboardProc,不过对于ctrl+alt+del好像是无效的,下面是一个例子:<br><br>LRESULT CALLBACK LowLevelKeyboardProc(<br> INT nCode, WPARAM wParam, LPARAM lParam)<br>{<br>&nbsp; &nbsp; // By returning a non-zero value from the hook procedure, the<br>&nbsp; &nbsp; // message does not get passed to the target window<br>&nbsp; &nbsp; KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *)lParam;<br>&nbsp; &nbsp; BOOL bControlKeyDown = 0;<br> <br>&nbsp; &nbsp; switch (nCode) {<br> case HC_ACTION: <br> // Check to see if the CTRL key is pressed<br> bControlKeyDown = <br> GetAsyncKeyState(VK_CONTROL) &gt;&gt; ((sizeof(SHORT) * 8) - 1);<br> <br> // Disable CTRL+ESC<br> if (pkbhs-&gt;vkCode == VK_ESCAPE &amp;&amp; bControlKeyDown) <br> return 1;<br> <br> // Disable ALT+TAB<br> if (pkbhs-&gt;vkCode == VK_TAB &amp;&amp; pkbhs-&gt;flags &amp; LLKHF_ALTDOWN)<br> return 1;<br> <br> // Disable ALT+ESC<br> if (pkbhs-&gt;vkCode == VK_ESCAPE &amp;&amp; pkbhs-&gt;flags &amp; LLKHF_ALTDOWN)<br> return 1;<br> <br> // Disable Win<br> if (pkbhs-&gt;vkCode == VK_LWIN || pkbhs-&gt;vkCode == VK_RWIN)<br> return 1;<br><br> break;<br> <br> default:<br> break;<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; return CallNextHookEx(hLLKeyHook, nCode, wParam, lParam);<br>}<br>
 
在win2k下面ctrl+alt+del是关系到系统安全性的按键,<br>例如更改密码,登陆等等。<br>如果能够截取ctrl+alt+del那么我么就可以假冒一个登<br>陆窗体而截取密码。win2k的安全性就岌岌可危了。<br><br>所以ctrl+alt+del在win2k下面应该是不能截取的。
 
不过说回来,我看到过有人模拟了Ctrl+Alt+Delete,主要是在系统里广播消息WM_HOTKEY<br>PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG(MOD_ALT | MOD_CONTROL, VK_DELETE))<br>问题在于发消息的这个线程应该是属于WinLogon这个Desktop,所以,需要创建一个线程来发这个<br>消息。发消息之前,需要用OpenDesktop("Winlongon",...)创建一个Desktop,然后切换到这个创<br>建好的Desktop。发完消息,再切换回原先的Desktop
 
乌龙茶理解错误!<br><br>我意思是在登录完成后的禁止!<br>或者使鍵盘失效!只用鼠标
 
可不可以用汇编语言来实现切断键盘和机器的联系 ?
 
&gt;&gt;wlyft,<br>乌龙茶理解是对的,如果在登陆后可以屏蔽,那么在登陆前也就可以<br>仿造一个登陆窗口用来窃取密码信息了.98下有不少黑客程序就是<br>利用了这种方式.<br>关于在两千下的屏蔽问题,我也很想知道答案<br>你们不觉得2000下的屏保很奇怪吗?它是怎么屏蔽的?
 
Phoenix2000的办法不行吗?
 
需要说明一个问题,在 NT/2000 下的屏幕保护程序与系统安全是挂钩的,具体使用了什么<br>方法不知道,比 Win9x 下的屏保安全机制复杂得多。换个思路,也就是在于能否在 NT/2000<br>下认为触发系统进入屏幕保护状态(当然进入屏保状态而不运行屏保程序),这和在 Win9x<br>中肯定不一样,要么这方面资料很少,要么就是微软没有公开这个相关的 API 函数接口,君<br>不见由第三方开发的 NT/2000 的屏幕保护程序少的可怜吗?这也是正常的,如果微软公开这<br>个接口(或者实现方法),那么NT/2000 的安全将行同虚设。所以说 Ctrl+Alt+Del 在 NT/2000<br>下理论上是可以捕获的,不一定非要用低级钩子这种方法,因为系统有可能的确对这个组合键作<br>特殊处理,使它可以不被任何非系统内核处理的钩子所捕获,但是用屏保的老办法可以,但是<br>不知道 NT/2000 的屏保与系统安全认证机制的接口或者联系,也是枉然。
 
那些隐藏的win api函数是怎么找出来的?
 
请问Phoenix2000:<br><br>Hook单元在什么地方呢?
 
我想知道hook单元模块在什么地方,另外将alt+esc,ctr+esc,alt+tab键切换到其他应用程序
 
好象用VC可以啊,用WH_KEYBOARD_DLL可以,但是在DELPHI下这个钩子不能用
 
多人接受答案了。
 
后退
顶部