You can search using the Process32First / Process32Next from windows, doing a loop in existing processes to search for the name of the executable for example. For your case you could do a Java search first, then make a second loop in the child processes (comparing the parent process ID) to see if your application is running.
Example:
uses
TlHelp32, System.Generics.Collections;
function RetornaPID(exeFileName: string): integer;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
Result := -1;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while Integer(ContinueLoop) <> 0 do
begin
if (UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName))
or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName)) then
begin
Result := FProcessEntry32.th32ProcessID;
break;
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
Function RetornaListaprocessosFilhos(aIDProcessoPai: Integer): TList<Integer>;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
Result := TList<Integer>.Create;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, aIDProcessoPai);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while Integer(ContinueLoop) <> 0 do
begin
if FProcessEntry32.th32ParentProcessID = aIDProcessoPai then
begin
Result.add(FProcessEntry32.th32ProcessID);
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
vPIDPai: Integer;
vPIDFilho: Integer;
vListaProcessosFilhos: TList<Integer>;
begin
vPIDPai := RetornaPID('explorer.exe');
if vPIDPai <> -1 then
begin
vListaProcessosFilhos := RetornaListaprocessosFilhos(vPIDPai);
for vPIDFilho in vListaProcessosFilhos do
begin
ShowMessage(format('Id do processo filho: %d', [vPIDFilho]));
end;
FreeAndNil(vListaProcessosFilhos);
end
else
ShowMessage('process não encontrado');
end;
Process32 ... Reference: DelphiTricks