有没有办法检测调试器是否附加到C#中的进程? [英] Is there a way to detect if a debugger is attached to a process from C#?
问题描述
有时我选择将调试器附加到已启动的程序。在这些情况下,我不希望过程在N秒后关闭。
我希望主机程序检测调试器是否附加,所以它可以选择不关闭它。
澄清:我不是要检测调试器是否附加到我的进程,我我想要检测一个调试器是否附加到我产生的进程中。
你将需要 P / Invoke 到 CheckRemoteDebuggerPresent 。这需要对目标进程的处理,您可以从Process.Handle获取。
I have a program that Process.Start()'s another program, and it shuts it down after N seconds.
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.
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.
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屋!