Announcement

Collapse
No announcement yet.

Feststellen ob ein bestimmtes Programm gestartet ist.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Feststellen ob ein bestimmtes Programm gestartet ist.

    Wie kann ich in einer Delphi Applikation feststellen ob ein bestimmtes Programm gestartet ist. Ich weiß nur den Namen der EXE. Ich weiß weder den Pfad noch den Fensternamen (Also FindWindow fällt weg).

    Andreas

  • #2
    Hallo, versuche es mal über die Applikationen im Taskmanager<BR>

    uses PsApi;<BR>

    function CheckProgIsRunnig (AppName : String) : Boolean;<BR>
    var<BR>
    i : Integer;<BR>
    pidNeeded : DWORD;<BR>
    PIDList : array[0..1000] of Integer; // Obergrenze !!!<BR>
    PIDName : array [0..MAX_PATH - 1] of char;<BR>
    PH : THandle;<BR>
    re : Boolean;<BR>
    AppCnt : Byte;<BR>
    begin<BR>
    AppCnt := 0;<BR>
    re := False;<BR>

    if not Psapi.EnumProcesses(@PIDList, 1000, pidNeeded) then<BR>
    exit;<BR>

    // raise Exception.Create('PSAPI.DLL ist nicht vorhanden!');<BR>
    for i := 0 to (pidNeeded div sizeof (Integer)- 1) do<BR>
    begin<BR>
    PH := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
    False, PIDList[i]);<BR>
    if PH <> 0 then<BR>
    begin<BR>
    if Psapi.GetModuleBaseName(PH, 0, PIDName, sizeof (PIDName)) > 0 then<BR>
    begin<BR>
    if UpperCase(StrPas(PIDName)) = AppName then Inc(AppCnt);<BR>
    // ListBox1.Items.Add('process : ' + PIDName);<BR>
    CloseHandle(PH);<BR>
    end;<BR>
    end;<BR>
    end;<BR>
    if AppCnt > 1 then Re := True;<BR>
    Result := re;<BR>
    end;<BR>

    Procedure TForm1.Button1Click(Sender ....);<BR>
    if CheckProgIsRunnig ('PROJECT1.EXE') = True then begin<BR>
    .....<BR>
    end;<BR>
    end;<BR>

    Gruß<BR>
    Matthias<BR&gt

    Comment


    • #3
      Hallo Matthias,

      schönen Dank für deine Funktion. Klappt prima :-)

      Ich mußte allerdings die Zeile

      if AppCnt > 1 then Re := True;
      in
      if AppCnt >= 1 then Re := True;

      abändern.

      Gruß
      Andrea

      Comment

      Working...
      X