有没有办法检测调试器是否附加到C#中的进程? [英] Is there a way to detect if a debugger is attached to a process from C#?

查看:470
本文介绍了有没有办法检测调试器是否附加到C#中的进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序是Process.Start()的另一个程序,它在N秒后关闭它。



有时我选择将调试器附加到已启动的程序。在这些情况下,我不希望过程在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆