简体   繁体   English

如何拦截所有关键事件,包括 ctrl+alt+del 和 ctrl+tab?

[英]How can I intercept all key events, including ctrl+alt+del and ctrl+tab?

I'm writing a screen saver type app that needs to stop the user from accessing the system without typing a password.我正在编写一个屏幕保护程序类型的应用程序,它需要阻止用户在不输入密码的情况下访问系统。 I want to catch/supress the various methods a user might try to exit the application, but all research I do seems to point me to "you can't".我想捕获/抑制用户可能尝试退出应用程序的各种方法,但我所做的所有研究似乎都指向我“你不能”。

Anything in C# or C++ would be great. C# 或 C++ 中的任何东西都会很棒。 I've thought of disabling the keyboard, but then I would have other issues.我曾想过禁用键盘,但随后我会遇到其他问题。

You can't.你不能。 The whole point of Ctrl+Alt+Del is that only the system gets to handle it, 'cause that way the system can always handle it. Ctrl+Alt+Del 的全部意义在于只有系统可以处理它,因为这样系统始终可以处理它。

Fortunately, Windows has built-in support for password-protected screensavers (available as the "On resume, password protect" option in Display Properties, or via group policy).幸运的是,Windows 内置了对受密码保护的屏幕保护程序的支持(可作为“显示属性”中的“恢复时,密码保护”选项或通过组策略使用)。 Just use that.就用那个。

To add to what Shog9 said, if your application could intercept ctrl+alt+del, then your application would be able to pretend to be the Windows Login dialog, and by doing so trick the end-user into typing their credentials into your application.补充一下 Shog9 所说的,如果您的应用程序可以拦截 ctrl+alt+del,那么您的应用程序将能够伪装成 Windows 登录对话框,并通过这样做来诱骗最终用户将他们的凭据输入到您的应用程序中。

If you do want to replace the Windows Login dialog, see Winlogon and GINA (but this says, "GINA DLLs are ignored in Windows Vista", and I haven't heard what's what for Vista).如果您确实想替换 Windows 登录对话框,请参阅Winlogon 和 GINA (但这表示“在 Windows Vista 中忽略 GINA DLL”,我还没有听说 Vista 是什么)。

if someone asked I'd not tell them they can't.如果有人问我不会告诉他们他们不能。

More specifically, your "application software" can't: instead, by design, only "system software" can do this;更具体地说,你的“应用软件”不能:相反,按照设计,只有“系统软件”可以做到这一点; and it isn't that you're not allowed to or not able to write system software, but your OP seemed to be quite clearly asking how to do it without writing system software ... and the answer to that is that you can't: because the system is designed to prevent an application from hooking these key combinations.它不是,你不能或不能写系统软件,但你的OP似乎很清楚,询问如何做到这一点,而无需编写系统软件......而答案,你可以” t:因为系统旨在防止应用程序挂钩这些组合键。

Can you give me direction to writing the system things.. I actually think this would be better if it were system level.. It's for an OEM so kind of the point really.你能给我指导编写系统的东西吗..我实际上认为如果它是系统级别的会更好..这对于OEM来说真的很重要。 Also if I wrote it system level, I could write an app to control it.此外,如果我在系统级别编写它,我可以编写一个应用程序来控制它。

A keyboard filter device driver, or a GINA DLL, for example, would be considered system software: installed by an administrator (or OEM) and run as part of the O/S.例如,键盘过滤器设备驱动程序或 GINA DLL 将被视为系统软件:由管理员(或 OEM)安装并作为 O/S 的一部分运行。

I don't know about GINA beyond its name;除了它的名字,我不知道 GINA; and I've already (above) given a link it in MSDN.我已经(上面)在 MSDN 中给出了一个链接。 I expect that it's Win32 user-mode code.我希望它是 Win32 用户模式代码。

Device drivers are a different topic: eg Getting Started on Driver Development .设备驱动程序是一个不同的主题:例如驱动程序开发入门

Is there a way to remap the keyboard so that delete isn't where it was?有没有办法重新映射键盘,以便删除不在原来的位置?

I still not sure that you and/or your boss have the right idea.我仍然不确定您和/或您的老板是否有正确的想法。 IMHO you shouldn't be an application which prevents the user from pressing Ctrl-Alt-Del.恕我直言,您不应该成为阻止用户按 Ctrl-Alt-Del 的应用程序。 If you want to stop the user from accessing the system without typing a password, then you ought to lock (password-protect) the system, as if the user had pressed Ctrl Alt Del and then selected "Lock this computer".如果您想阻止用户在不输入密码的情况下访问系统,那么您应该锁定(密码保护)系统,就像用户按下了 Ctrl Alt Del 然后选择了“锁定这台计算机”一样。 To unlock the computer they would then need to press Ctrl Alt Del and enter their credentials into WinLogon.要解锁计算机,他们需要按 Ctrl Alt Del 并在 WinLogon 中输入他们的凭据。

However, ignoring what you ought to do and concentrating instead on what you're capable of doing, if you want to intercept the keyboard, apparently it can be done.然而,忽略你应该做的,而是专注于你能做的,如果你想拦截键盘,显然是可以做到的。 I haven't studied keyboards myself, but this post and this post claim success, by writing a "Keyboard Filter Driver" (which is a kind of kernel-mode, not Win32, device driver).我自己没有研究过键盘,但是这篇文章这篇文章声称成功,通过编写“键盘过滤器驱动程序”(这是一种内核模式,而不是 Win32 设备驱动程序)。 If you write one of these though you may get some push-back, eg like this reaction from a DDK MVP , or this reaction from an anti-snooping product .如果您编写其中之一,尽管您可能会受到一些回击,例如来自 DDK MVP 的这种反应,或者来自反窥探产品的这种反应

I have not tested it but what about using SetWindowsHookEx()我还没有测试过,但是如何使用 SetWindowsHookEx()

From MSDN documentantion: WH_KEYBOARD_LL来自 MSDN 文档:WH_KEYBOARD_LL

Windows NT/2000/XP: Installs a hook procedure that monitors low-level keyboard input events. Windows NT/2000/XP:安装一个钩子程序来监视低级键盘输入事件。 For more information, see the LowLevelKeyboardProc hook procedure.有关详细信息,请参阅 LowLevelKeyboardProc 挂钩过程。

As this seems to be a good collection spot for the accrual of various means with which to "intercept" the three key psuedo-break control alt delete, here is something I encountered yesterday that may be of use.由于这似乎是“拦截”三个关键伪中断控制 alt 删除的各种方法的累积的好收集点,这是我昨天遇到的可能有用的东西。

http://cuinl.tripod.com/Tips/enablectrldel.htm http://cuinl.tripod.com/Tips/enablectrldel.htm

In my opinion , when it seems that the only practical and timely option is to cut the power (ie MECHANICAL removal of the battery of an overloaded android-like handheld computer) to halt whatever procession or malfunction results in rather solid and complete ( or long enduring) irresponsiveness-- it appears that a dangerous and frustrating lineage continues--- and continues to get worse.在我看来,当似乎唯一实用和及时的选择是切断电源(即机械移除过载的类 android 掌上电脑的电池)以停止导致相当稳定和完整(或长时间)的任何进程或故障时持久)反应迟钝——似乎危险和令人沮丧的血统仍在继续——并且继续变得更糟。

Especially with the removal of sensible and straightforward things like mechanical speaker volume controls.尤其是移除了诸如机械扬声器音量控制之类的明智而直接的东西。 ( sure, bulky, more material, but of course that is just the thing, what good to an individual or being is infinite and perfect consciousness without a handle on it or it's experience?) (当然,笨重,更多物质,但当然这就是事情,对个人或存在有什么好处,无限和完美的意识没有处理它或它的经验?)

It is a lineage of approaches to designing the -environment that is responsible for the responsiveness to the user- part of a critical and truly meaningful technological interface.它是设计环境的一系列方法,负责响应用户的关键和真正有意义的技术界面部分。 ( The only?) ( 唯一的?)

I say put some buttons --direct-to-hardware-control-- back on the things --at least until the software aspects of these technologies become fully adapted to artificial soft interfacing, which I account for in an exhaustive accounting of all heuristical provisionings.我说把一些按钮——直接到硬件控制——放回原处——至少在这些技术的软件方面完全适应人工软接口之前,我在对所有启发式的详尽说明中解释了这一点供应。

Even in the mechanics of the universe I bet there's a handy reset, restore, suspend, halt type of function(s) for the safety and fundamental viability of the presence of what would constitute as the designer of all that follows the initiating perpetual mystery of existence: INTELLIGENT AWARENESS and WILL.即使在宇宙的力学中,我敢打赌有一个方便的重置、恢复、暂停、停止类型的功能,以确保存在的安全性和基本可行性存在:智能意识和意志。

It is possible to intercept crtl+alt+del, though obviously Microsoft made it very difficult to do, because then you could pop-up a fake lock dialog, and record people's passwords.拦截crtl+alt+del是可能的,虽然很明显微软很难做到,因为那样你就可以弹出一个假的锁定对话框,并记录人们的密码。

The answer is to write a device driver.答案是编写设备驱动程序。 I can't remember if you can just use a plain old keyboard filter, or if you have to write a keyboard ISR.我不记得你是否可以只使用一个普通的旧键盘过滤器,或者你是否必须编写一个键盘 ISR。 Either way, its certainly possible, but with great pain if you have no driver experience.无论哪种方式,这当然是可能的,但是如果您没有驾驶经验,那会非常痛苦。

"Process Explorer" by Mark Russinovich (http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) does it, and it had been doing before Sysinternals was bought by Microsoft. Mark Russinovich (http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) 的“Process Explorer”就是这样做的,并且在 Sysinternals 被微软收购之前就已经这样做了。

This article from 2002 updated in 2006 explains one way to do it without writing a keyboard driver.这篇 2002 年更新的文章于 2006 年更新,解释了一种无需编写键盘驱动程序即可完成此操作的方法。 http://www.codeproject.com/KB/system/preventclose.aspx?msg=1666328 http://www.codeproject.com/KB/system/preventclose.aspx?msg=1666328

starting taskmgr.exe in hidden window would do the job if you just wanted to suppres the call to task manager如果您只想抑制对任务管理器的调用,则在隐藏窗口中启动 taskmgr.exe 即可完成这项工作

    ProcessStartInfo taskmgr = new ProcessStartInfo()
    {
        FileName = "taskmgr.exe",
        WindowStyle = ProcessWindowStyle.Hidden
    };

    Process.Start(taskmgr);

您可以在 XP 及之前实现这一点,但在 Vista 中则不再如此。

Try investigating if you could write an application that starts itself as a password protected screensaver.尝试调查您是否可以编写一个应用程序,将自身作为受密码保护的屏幕保护程序启动。

Screensavers can do more than just display pretty pictures - I've seen interactive screensavers before that used the mouse and keyboard to provide a simple game, though I can't remember which version of windows I saw this running on... It could well have been windows 95. (In which case all bets are off).屏保可以做的不仅仅是显示漂亮的图片 - 我之前见过交互式屏保,使用鼠标和键盘来提供一个简单的游戏,虽然我不记得我看到它运行在哪个版本的 Windows 上......它很可能一直是windows 95。(在这种情况下,所有赌注都关闭了)。

What about intercepting ctrl and alt keypresses while your program is running, and .cancel'ing those keypresses?在您的程序运行时拦截 ctrl 和 alt 按键,并取消这些按键怎么样?

I don't know how well this would work, if at all in Vista, but it's worth a try.我不知道这在 Vista 中会有多好,但它值得一试。

I remember doing something like this around the year 2001, so it was probably running on 98. Been too long since I've even tried to mess with anything like locking out ctrl-alt-del.我记得在 2001 年左右做过这样的事情,所以它可能在 98 上运行。自从我什至试图搞乱诸如锁定 ctrl-alt-del 之类的事情已经太久了。

Ok.. I'm not going to post the code here But the gyst is this好的..我不打算在这里发布代码但是gyst是这个

create a keyboard hook.创建一个键盘钩子。 when the user presses ctrl ||当用户按下 ctrl || alt ||替代 || delete set bools to true.. if they press anything else set them all to false. delete set bool to true .. 如果他们按下任何其他东西,将它们全部设置为 false。

switch (p_key)
            {
                default: Clear(); break;

                case Keys.LMenu: altHit = true; break;
                case Keys.RMenu: altHit = true; break;
                case Keys.LControlKey: ctrlHit = true; break;
                case Keys.RControlKey: ctrlHit = true; break;
                case Keys.Delete: delHit = true; break;

when the screen has focus looses it to the task manager, close the bloody thing.当屏幕有焦点时,将其交给任务管理器,关闭该死的东西。 The screen flashes so fast the user never notices it.屏幕闪烁得如此之快,以至于用户从未注意到。 And I can do what ever I want.我可以做任何我想做的事。

I'll admit this is a kludge, but it does result in the desired effect.我承认这是杂七杂八的,但它确实产生了预期的效果。 (OH I wish I didn't have to do this) (哦,我希望我不必这样做)

You can still intercept Ctrl + Alt + Del in windows 7.您仍然可以在 Windows 7 中拦截Ctrl + Alt + Del

This is the way Process explorer does it: Process explorer 是这样做的:

http://mygreenpaste.blogspot.com/2005/07/image-file-execution-options-good-evil.html http://mygreenpaste.blogspot.com/2005/07/image-file-execution-options-good-evil.html

I was reading this doc page, and some thought and searching brought me to this question.我正在阅读这个文档页面,一些思考和搜索让我想到了这个问题。

https://docs.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input https://docs.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input

I have not tested it, but there is this excerpt:我没有测试过,但有这个摘录:

As the name implies, system key strokes are primarily intended for use by the operating system.顾名思义,系统击键主要供操作系统使用。 If you intercept the WM_SYSKEYDOWN message, call DefWindowProc afterward.如果您截获 WM_SYSKEYDOWN 消息,请稍后调用 DefWindowProc。 Otherwise, you will block the operating system from handling the command.否则,您将阻止操作系统处理该命令。

Seems like a security hole to me if it actually works like it says.如果它真的像它说的那样工作,对我来说似乎是一个安全漏洞。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM