.NET 模拟 Ctrl+Alt+Del Sendkeys
标题中已经说了,如何模拟组合Ctrl+Alt+DEL?
我尝试过这个:
SendKeys.Send("^(%({DEL}))")
SendKeys.Send("^(%{DEL})")
SendKeys.Send("^%{DEL}")
但没有成功。我正在使用 VB.NET 和 Windows XP SP3
all is said in the title, how can I simulate the combination Ctrl+Alt+DEL?
I tried this:
SendKeys.Send("^(%({DEL}))")
SendKeys.Send("^(%{DEL})")
SendKeys.Send("^%{DEL}")
But none worked. I am working on VB.NET and Windows XP SP3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
从 Windows Vista 开始,您可以使用
SendSAS
函数。
原始答案,现已被上述答案取代
您需要的函数称为
SimulateSAS
。您需要发送电子邮件至 [email protected] 并索取。 Microsoft 似乎没有记录这一点,但只是对SimulateSAS
进行网络搜索 你就会明白我的意思了。其他人已经解释了为什么允许应用程序触发 CTRL+ALT+DEL 实际上不是安全问题,但你肯定不能这样做使用
SendKeys
。As of Windows Vista, you can use the
SendSAS
function.Original answer, now superseded by the above
The function you need is called
SimulateSAS
. You need to e-mail [email protected] and ask for it. Microsoft don't appear to document this, but just do a websearch forSimulateSAS
and you'll see what I mean.Others have explained why it's actually not a security issue to allow apps to trigger CTRL+ALT+DEL, but you certainly can't do it with
SendKeys
.你不能。这是在设备驱动程序级别完成的,您不能伪造键盘驱动程序的输入。这也是您无法禁用它的原因。允许它被伪造当然会是一个非常严重的安全缺陷。
You can't. This is done at the device driver level, you can't fake input for the keyboard driver. Also the reason you cannot disable it. Allowing it to be faked would of course be a very serious security flaw.
您最好的选择可能是下载 TightVNC 源代码,看看他们是如何做到的。
Your best bet might be to download the TightVNC source code, and see how they do it.
请参阅此线程以获取一些似乎有用的信息:
基本上:
然后您的程序可以使用以下未记录的 API 来调用它:
注意,我只提取了链接到的网页,我不知道它是否有效,或者是否还有更多问题。
See this thread for some information that seems useful:
Basically:
Your program can then use the following undocumented API to invoke it:
Note, I only distilled the web page I link to, I have no idea if it works, or if there are more gotchas.
从 Windows Vista 开始,
SendSAS
功能可用。As of Windows Vista, the
SendSAS
function is available.我终于找到了 此 C++ 代码,以系统用户身份启动时效果很好。因此,我将代码转换为 dll,并从我的代码中调用该函数。
下面是 C++ 代码(您可以使用 ErrorExit 示例函数,该函数使用 MSDN 中的
GetLastError
,以防出现问题):您还需要将 .def 文件添加到正确导出函数的项目(项目名为AltCtrlDelCpp)并告诉链接器模块的定义文件就是这个文件
然后,在.NET解决方案中,将dll添加到项目中,对其进行配置,使其始终复制到输出目录中,只需使用 DllImport 导入该函数即可:
C# 代码
VB.NET 代码
在 VB.NET 中,还需要将属性添加到Sub Main :
然后您只需调用 SimulateAltControlDel 函数即可。请注意,我仅适用于控制台应用程序,它不适用于 winform 应用程序。
I finally found this C++ code on CodeProject, which works well when launched as System user. Therefore, I converted the code into a dll, and called the function from my code.
Here is the c++ code (you can use the ErrorExit example function that uses
GetLastError
from MSDN in case a problem occured):You also need to add a .def file to the project to export the function correctly (the project is named AltCtrlDelCpp) and tell the linker that the definition file of the module is this file
Then, in the .NET solution, you add the dll to the project, configures it so that it is always copied in the output directory, and you just use DllImport to import the function:
C# Code
VB.NET Code
In VB.NET, you also need to add the attribute to the Sub Main :
Then you just have to call the
SimulateAltControlDel
function and there you go. Please note that I had this work only for a Console Apps, it didn't work in winform apps.