【发布时间】:2014-09-26 16:42:35
【问题描述】:
使用System.Diagnostics.Debugger.Debugger.IsAttached 我可以看出附加了一个调试器。有没有办法检测附加的调试器是否是远程调试器(Visual Studio Remote Debugger Monitor)?
【问题讨论】:
标签: c# .net visual-studio remote-debugging
使用System.Diagnostics.Debugger.Debugger.IsAttached 我可以看出附加了一个调试器。有没有办法检测附加的调试器是否是远程调试器(Visual Studio Remote Debugger Monitor)?
【问题讨论】:
标签: c# .net visual-studio remote-debugging
你可以使用来自kernel32.dll的原生CheckRemoteDebuggerPresent
来自MSDN:
CheckRemoteDebuggerPresent 中的“远程”并不意味着 调试器必须驻留在不同的计算机上;相反,它 表示调试器驻留在单独的并行 过程。
您可以按如下方式使用它:
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CheckRemoteDebuggerPresent(IntPtr hProcess, ref bool isDebuggerPresent);
public static void Main()
{
bool isDebuggerPresent = false;
CheckRemoteDebuggerPresent(Process.GetCurrentProcess().Handle, ref isDebuggerPresent);
Console.WriteLine(string.Format("Debugger Attached: {0}", isDebuggerPresent));
Console.ReadLine();
}
【讨论】: