Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#32

AW: In welchem Pfad läuft ein Prozess?

  Alt 26. Okt 2018, 22:25
Komisch, also wenn bei Dir Edit1.Text einen guten Namen wie "Explorer.exe" annimmt aber "xyz.exe" nicht, obwohl mein processlister "xyz.exe" anzeigen kann, da fällt mir nichts weiter zu ein.
Ich nutz identischen Code zum ermitteln der Prozesse, da passiert genau das gleiche, nur das ich in der Schleife alle Prozesse sammel und System-Prozesse gleich rauswerfe (die sind bei Dir noch enthalten), das ist der einzige Unterschied.

So hier müsste es klappen das bei systemprozessen du keine AV bekommst, habs grad nicht getestet, nur hier im editor.
Delphi-Quellcode:
function ProcessExists(const AFileName: WideString; var FoundFiles: TStringList; out HostIndex: Integer): Boolean;
var
  ContinueLoop: BOOL;
  FSnapshotHandle: THandle;
  FProcessEntry32: TProcessEntry32;
  fullPath: WideString;
  myPID: DWORD;
  OwnPID: Cardinal;
begin
  HostIndex := -1;
  FoundFiles := TStringList.Create;
  OwnPID := GetCurrentProcessId;
  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
  ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
  Result := False;
  while Integer(ContinueLoop) <> 0 do
  begin
    Try
    if UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExtractFileName(AFileName)) then
    begin
      myPID := FProcessEntry32.th32ProcessID;
      fullPath := PidToFilename(myPID);
      FoundFiles.Add(fullPath);
      if myPID = OwnPID then
      begin
        HostIndex := FoundFiles.Count-1;
        Result := True;
      end;
    end;
    ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
    Except
      ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
    End;
  end;
  CloseHandle(FSnapshotHandle);
end;
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat