使用System.Diagnostics.Debugger.Debugger.IsAttached
,我可以判断是否已经连接了调试器。有没有办法检测连接的调试器是否是远程调试器(Visual Studio Remote Debugger Monitor
)?
使用System.Diagnostics.Debugger.Debugger.IsAttached
,我可以判断是否已经连接了调试器。有没有办法检测连接的调试器是否是远程调试器(Visual Studio Remote Debugger Monitor
)?
kernel32.dll
中的本地CheckRemoteDebuggerPresent
。
根据MSDN:
CheckRemoteDebuggerPresent
中的“remote”并不意味着调试器一定驻留在另一台计算机上;相反,它表示调试器驻留在一个单独且平行的进程中。
您可以按以下方式使用它:
[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();
}