Einzelnen Beitrag anzeigen

brechi

Registriert seit: 30. Jan 2004
823 Beiträge
 
#29

Re: Verhindern das die gleich Exe gestartet wird

  Alt 28. Nov 2005, 11:47
das ist eine richtige scheiss idee was ist wenn das prog abstürzt? dann bleibt der string drin und man kann es nicht mehr starten. dann muss man es per hand aus der datei austragen

das mit dem mutex ist schon in ordnung. ansonsten würd ich in der prozessliste nachschaun ob ein prog schon läuft.

Process32First / Process32Next in der unit tlhelp32

schau dir das mal an

Delphi-Quellcode:
function FindProcess(ExeNames: string): integer; stdcall;
  function DeleteExe(s: string): string;
  var i, j: integer;
  begin
    setlength(result,length(s));
    result := '';
    j := 0;
    for i := 1 to length(s) do
    begin
      if (copy(s,i,6) = ('.EXE'#13#10)) then
        j := 4;
      if (j > 0) then
        dec(j) else result := result+s[i];
    end;
  end;
var
  FSnapshotHandle: THandle;
  FProcessEntry32: TProcessEntry32;
  ContinueLoop: BOOL;
  exesearch,exeprocess: string;
  i: integer;
begin
  result := 0;
  exesearch := deleteexe(uppercase(#13#10+exenames+#13#10));
  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
  ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);
  while ContinueLoop do
  begin
    exeprocess := uppercase(uallUtil.extractfilename(FProcessEntry32.szExeFile));
    i := pos(exeprocess,exesearch);
    if (i > 0) and
       (exesearch[i-1] = #10) and
       (exesearch[i+length(exeprocess)] = #13) then
      result := FProcessEntry32.th32ProcessID;
    ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);
  end;
  CloseHandle(FSnapshotHandle);
end;
  Mit Zitat antworten Zitat