Thema: Delphi Pfad über Prozess

Einzelnen Beitrag anzeigen

Benutzerbild von MuTzE.Y85
MuTzE.Y85

Registriert seit: 11. Apr 2006
152 Beiträge
 
#7

Re: Pfad über Prozess

  Alt 10. Sep 2006, 22:07
So hier noch nen bissel sauberer. Funktionieren aber beide.

Delphi-Quellcode:
function GetProcessPath(Exename: string): String;
var
  hProcSnap, hModSnap: THandle;
  PE32: TProcessEntry32;
  ME32: TModuleEntry32;
begin
  Result := '';
  hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
  if hProcSnap <> INVALID_HANDLE_VALUE then
   begin
    PE32.dwSize := SizeOf(ProcessEntry32);
    if Process32First(hProcSnap, PE32) = True then
     begin
      while Process32Next(hProcSnap, PE32) = True do
       begin
        if Pos(Exename, PE32.szExeFile) <> 0 then
         begin
          hModSnap := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PE32.th32ProcessID);
          if hModSnap <> INVALID_HANDLE_VALUE then
           begin
            ME32.dwSize := SizeOf(TModuleEntry32);
            if Module32First(hModSnap, ME32) = True then
             Result := ME32.szExePath;
           end;
          CloseHandle(hModSnap);
         end;
       end;
     end;
    CloseHandle(hProcSnap);
   end;
end;
  Mit Zitat antworten Zitat