Windows API : IsDebuggerPresent

This function checks specific flag in the Process Environment Block (PEB) for the field IsDebugged which will return zero if the process is not running into a debugger or a nonzero if a debugger is attached.

If you want to understand the underlying process of IsDebuggerPresent API you can check the code snippet section for the following method: IsDebugged Flag.

Code Snippets

#include <windows.h>
#include <stdio.h>

int main(int argc, char** argv)
{
	if (IsDebuggerPresent())
	{
            printf("Debugger detected!!\n");
	}
	else
	{
	    printf("No debugger detected!!\n");
	}
	system("pause");
	return 0;
}
program IsDebuggerPresent;

{$APPTYPE CONSOLE}

uses
  WinAPI.Windows, System.SysUtils;

begin
  try
    if IsDebuggerPresent() then
      WriteLn('Process is currently getting debugged.')
    else
      WriteLn('Process is not likely getting debugged.');

    readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Additional Resources

Subscribe to our Newsletter and don't miss important updates