有没有一种方法,如果一个调试器附加到从C#的过程来检测? [英] Is there a way to detect if a debugger is attached to a process from C#?
问题描述
我有一个程序,的Process.Start()的另一个程序,它N秒后关闭它。
I have a program that Process.Start()'s 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.
澄清:我不是在寻找,如果调试器附加到的我的的过程中进行检测,我在找,如果一个调试器附加到我催生了过程检测。
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/Invoke 下来的 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屋!