How do you determine at runtime whether the visual studio debugger is attached to your process. I've seen instructions for how to do this in .NET, but my process is a native C++ process. Support for detecting Just-in-time debugging would be nice but not a strict requirement.
Asked
Active
Viewed 1,503 times
5
-
Are you asking for a way to detect if the debugger is attached from within the process the debugger is attached to, or from a different outside process? – tloach May 07 '10 at 14:48
-
from inside the process the debugger is attached to. IsDebuggerPresent worked as suggested below. – Jeremy Bell May 07 '10 at 15:34
-
possible duplicate of http://stackoverflow.com/questions/101806/check-if-application-was-started-from-within-visual-studio – Suma May 07 '10 at 17:07
-
1not really a dupe (although the IsDebuggerPresent function was mentioned) - that question was for .net specifically. This is for C++/Win32. – Jeremy Bell May 07 '10 at 17:31
2 Answers
14
The Win32 call IsDebuggerPresent()
sounds like it ought to work.

unwind
- 391,730
- 64
- 469
- 606
-
I used this approach but then saw the blog in the following link where he claims he dissabled IsDebuggerPresent through a script, so this approach can be problematic: https://blogs.msdn.microsoft.com/debuggingtoolbox/2007/05/23/windbg-script-disabling-isdebuggerpresent/ – TBD Mar 22 '16 at 06:31
4

Nikola Smiljanić
- 26,745
- 6
- 48
- 60
-
+1 for being the right answer, even if 2 minutes later than unwind's answer. Thanks to you also. – Jeremy Bell May 07 '10 at 15:09