如何向系统发出 ctrl-alt-del 按键?(50分)

  • 主题发起人 主题发起人 mycoolis2
  • 开始时间 开始时间
看来很多人有这个要求,5.5至今已有3人提出。但问题好象很难解决。<br>可以肯定,用API的方式在Windows98是行不通的。<br>在WIndows &nbsp;NT 下应该是可以实现的。但是,我试过N次,都fail.<br><br>其一:<br>var <br>HDesk_WL: HDESK; <br>begin <br>HDesk_WL := OpenDesktop ('Winlogon', 0, False, DESKTOP_JOURNALPLAYBACK); <br>if (HDesk_WL &lt;&gt; 0) then <br>begin <br>{we have open the Winlogon Desktop so assign it to our thread} <br>if (SetThreadDesktop (HDesk_WL) = True) then <br>begin <br>// Winlogon uses hotkeys to trap Ctrl-Alt-Del... <br>PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG (MOD_ALT or MOD_CONTROL, VK_DELETE));<br>end<br>end<br>end;<br><br>其二:<br><br><br>&nbsp; SK_DEL = #249;<br>&nbsp; SK_SHIFT_DN = #250;<br>&nbsp; SK_SHIFT_UP = #251;<br>&nbsp; SK_CTRL_DN = #252;<br>&nbsp; SK_CTRL_UP = #253;<br>&nbsp; SK_ALT_DN = #254;<br>&nbsp; SK_ALT_UP = #255;<br><br>procedure SendKeyString(Text: String);<br>var<br>&nbsp; &nbsp;i: Integer;<br>&nbsp; &nbsp;Shift: Boolean;<br>&nbsp; &nbsp;vk, ScanCode: Word;<br>&nbsp; &nbsp;ch: Char;<br>&nbsp; &nbsp;c, s: Byte;<br>const<br>&nbsp; &nbsp;vk_keys: Array[0..9] of Byte =<br>&nbsp; &nbsp; &nbsp; (VK_HOME, VK_END, VK_UP, VK_DOWN, VK_LEFT,<br>&nbsp; &nbsp; &nbsp; &nbsp;VK_RIGHT, VK_PRIOR, VK_NEXT, VK_INSERT, VK_DELETE);<br>&nbsp; &nbsp;vk_shft: Array[0..2] of Byte = (VK_SHIFT, VK_CONTROL, VK_MENU);<br>&nbsp; &nbsp;flags: Array[False..True] of Integer = (KEYEVENTF_KEYUP, 0);<br>begin<br>&nbsp; &nbsp;Shift := False;<br>&nbsp; &nbsp;for i := 1 to Length(Text) do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;ch := Text;<br>&nbsp; &nbsp; &nbsp;if ch &gt;= #250 then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;s := Ord(ch) - 250;<br>&nbsp; &nbsp; &nbsp; &nbsp;Shift := not Odd(s);<br>&nbsp; &nbsp; &nbsp; &nbsp;c := vk_shft[s shr 1];<br>&nbsp; &nbsp; &nbsp; &nbsp;ScanCode := MapVirtualKey(c,0);<br>&nbsp; &nbsp; &nbsp; &nbsp;Keybd_Event(c, Scancode, Flags[shift], 0);<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;vk := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp;if ch &gt;= #240 then<br>&nbsp; &nbsp; &nbsp; &nbsp; c := vk_keys[Ord(ch) - 240]<br>&nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; if ch &gt;= #228 then {228 (F1) =&gt; $70 (vk_F1)}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;c := Ord(ch) - 116<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ch &lt; #110 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c := Ord(ch)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;vk := VkKeyScan(ch);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;c := LoByte(vk);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp;ScanCode := MapVirtualKey(c,0);<br>&nbsp; &nbsp; &nbsp; &nbsp;if not Shift and (Hi(vk) &gt; 0) then { $2A = scancode of VK_SHIFT }<br>&nbsp; &nbsp; &nbsp; &nbsp; Keybd_Event(VK_SHIFT, $2A, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;Keybd_Event(c,scancode, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;Keybd_Event(c,scancode, KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;if not Shift and (Hi(vk) &gt; 0) then<br>&nbsp; &nbsp; &nbsp; &nbsp; Keybd_Event(VK_SHIFT, $2A, KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>end;<br><br>procedure SendKeysToHandle(WindowHandle: hWnd; Text: String);<br>begin<br>&nbsp; MakeWindowActive(WindowHandle);<br>&nbsp; SendKeyString(Text);<br>end;<br><br>执行:SendKeysToHandle(HWAND_BROACAST,SK_CTRL_DN + SK_Alt_DN + SK_DEL )<br>fail ?!!!!<br><br>why ???
 
好像以前的讨论结果是——这三个组合键不是消息,已经被系统接管了,不可能简单的模拟。<br>在WinNT下也是不可能的(Win2K Advanced Server在登录之前必须让用户按下这个组合键,<br>如果可能被模拟...)。<br><br>VMware可以在一个操作系统中运行另一个操作系统,并且可以截获主系统中的ctrl-alt-del,<br>或者在模拟运行的子操作系统中模拟ctrl-alt-del。看来实现肯定是可以的,只不过要编底层<br>驱动了。
 
仔细看看MSDN吧!某些系统按键已经被系统自身完全接管了!简单模拟是无效的!<br>你既然要向系统发出 ctrl-alt-del 按键信息,我想结果无非是要重启系统!<br>如果是这样,又何必绕那么大的圈子呢???
 
creation-zy:<br>WIN2K下,每次启动可以默认一个管理员帐号,跳过登录口令输入,那么这个是怎么通过的?<br>注册表、文件??<br><br>谁知道!:)
 
模拟按键Ctrl+Alt+Del是完全可行的,我看到过有程序模拟了Ctrl+Alt+Delete,主要是在系统里广<br>播消息WM_HOTKEY:PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG(MOD_ALT | MOD_CONTROL,<br>VK_DELETE)) 问题的关键在于发消息的这个线程应该是属于WinLogon这个Desktop,所以,需要创建一<br>个线程来发这个消息。在线程发消息之前,需要用OpenDesktop("Winlongon",...)创建一个Desktop,<br>然后切换到这个创建好的Desktop。发完消息,再切换回原先的Desktop。<br><br>不过那个程序是C++写的,叫VNC,很有名的远程控制软件,http://www.uk.research.att.com/vnc/上<br>有源码下载的。<br>
 
我觉得肯定是可以的,因为微软的NETMEETING就有发送CTRL+ALT+DELETE三键的功能。<br>
 
用softice拦截各种消息看看...
 
不用按这三个键,如何让那个按这三个键显示的“关闭程序”窗口出来?
 
好像在Win2000或NT下可以通过替换系统的GINA.DLL来实现。
 
xWolf的意见我非常赞成,模拟CTRL+ALT+DEL的完全可以的,PCANYWHERE,VNC就是现成的例<br>子,但用API来截获这三个键,虽不能说完全不可能,但至少是属于MS的未公开的API,因为<br>这三个键本来就是用来防止别人伪造登录窗口骗取密码的
 
是的,如果要截获这个三个键,就要用Gina了,我没有试过
 
后退
顶部