有没有办法检测调试器是否从C#附加到另一个进程? [英] Is there a way to detect if a debugger is attached to another process from C#?
问题描述
我有一个程序 Process.Start()
另一个程序,它在N秒后将其关闭。
I have a program that Process.Start()
another program, and it shuts it down after N seconds.
有时我选择将调试器附加到启动的程序。在那种情况下,我不想在N秒后关闭进程。
Sometimes I choose to attach a debugger to the started program. In those cases, I don't want the process shut down after N seconds.
我希望主机程序能够检测是否连接了调试器,因此它可以选择不关闭它。
I'd like the host program to detect if a debugger is attached or not, so it can choose to not shut it down.
说明:我不是要检测调试器是否已附加到 my 进程,我正在寻找是否将调试器附加到我产生的进程上。
Clarification: I'm not looking to detect if a debugger is attached to my process, I'm looking to detect if a debugger is attached to the process I spawned.
推荐答案
您将需要 P /调用到 CheckRemoteDebuggerPresent 。这需要目标进程的句柄,您可以从Process.Handle获取该句柄。
You will need to P/Invoke down to CheckRemoteDebuggerPresent. This requires a handle to the target process, which you can get from Process.Handle.
这篇关于有没有办法检测调试器是否从C#附加到另一个进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!