Detect wether an application is being dubugged or not.

The following function will detect if the application is being debugged or not. This function will not work on Windows 95.

Behaviour of an application could be changed if run within a debugger, for instance component writers might want their unregistered components to be run in the debugger only.

Answer:





function DebuggerPresent: boolean;

type

  TDebugProc = function: boolean; stdcall;

var

  Kernel32: HMODULE;

  DebugProc: TDebugProc;

begin

  Result := False;

  Kernel32 := GetModuleHandle('kernel32.dll');

  if Kernel32 <> 0 then

  begin

    @DebugProc := GetProcAddress(Kernel32, 'IsDebuggerPresent');

    if Assigned(DebugProc) then

      Result := DebugProc;

  end;

end;





to use a simple if test can be used



if DebuggerPresent then

  ShowMessage('debugging')

else

  ShowMessage('NOT debugging');

 

Share this article!

Follow us!

Find more helpful articles: