Question: I've heard that some custom component authors use an RTL routine that checks to see if Delphi is running in order to set up shareware restrictions. Does anyone know what this routine is? Checking obvious names like "DelphiRunning" or "IsDelphiRunning" doesn't turn up anything useful.

Answer: 
There are **2 different ideas** here:  

- Delphi is up and running  

- The application is running under the debugger

The common way to test if **Delphi is running** is to check the presence of known IDE Windows which have a specific classname like TAppBuilder or TPropertyInspector.  

Those 2 works in all version of Delphi IIRC. 

If you want to know if your application is **running under the debugger**, i.e. launched normally from the IDE with "Run" (F9) or attached to the debugger while already running, you just have to test the DebugHook global variable.  

Note that "Detach from program" does not remove the DebugHook value, but "Attach to process" sets it.

```
function IsDelphiRunning: Boolean;
begin
  Result := (FindWindow('TAppBuilder', nil) > 0) and
    (FindWindow('TPropertyInspector', 'Object Inspector') > 0);
end;

function IsOrWasUnderDebugger: Boolean;
begin
  Result := DebugHook <> 0;
end;

```

If the goal is to **restrict the use of a trial version** of your component to when the application is being developped, **both have flaws**:  

- Hidden windows with the proper Classname/Title can be included in the application  

- DebugHook can be manually set in the code
This is a code snippet from [www.delphitricks.com/source-code/misc/check\_if\_delphi\_is\_running.html](http://www.delphitricks.com/source-code/misc/check_if_delphi_is_running.html).

```
function WindowExists(AppWindowName, AppClassName: string): Boolean; 
var 
  hwd: LongWord; 
begin 
  hwd    := 0; 
  hwd    := FindWindow(PChar(AppWindowName), PChar(AppClassName)); 
  Result := False; 
  if not (Hwd = 0) then {window was found if not nil} 
    Result := True; 
end; 

function DelphiLoaded: Boolean; 
begin 
  DelphiLoaded := False; 
  if WindowExists('TPropertyInspector', 'Object Inspector') then 
    if WindowExists('TMenuBuilder', 'Menu Designer') then 
      if WindowExists('TAppBuilder', '(AnyName)') then 
        if WindowExists('TApplication', 'Delphi') then 
          if WindowExists('TAlignPalette', 'Align') then 
            DelphiLoaded := True; 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
  if DelphiLoaded then 
  begin 
    ShowMessage('Delphi is running'); 
  end; 
end; 

function DelphiIsRunning: Boolean; 
begin 
  Result := DebugHook <> 0; 
end;

```