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

查看:21
本文介绍了有没有办法检测调试器是否从 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.

澄清:我不想检测调试器是否附加到我的进程,我想检测调试器是否附加到我的进程生成.

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/InvokeCheckRemoteDebuggerPresent.这需要目标进程的句柄,您可以从 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屋!

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