Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Prozessinfos (https://www.delphipraxis.net/72754-prozessinfos.html)

silent vapor 6. Jul 2006 10:55


Prozessinfos
 
Hallo zusammen,

ich sehe vor lauter Bäumen den Wald nicht mehr.
Ich will zu einem Prozess z.B. "calc.exe" den Pfad ermitteln, wo diese Datei liegt.

Ich habe mich dazu mal auf http://www.swissdelphicenter.com/de/ umgesehen, habe auch einige Sachen gefunden.

Müsste theoretisch erst die ProzessID ermitteln und mir dann wie hier
http://www.swissdelphicenter.com/de/showcode.php?id=281

die Variable ImageName ausgeben.

Geht das nicht irgendwie in einem Zweizeiler? Das Programm soll so klein wie möglich werden.

Danke für jede Hilfe!

Gruß
silent

MartinA 6. Jul 2006 15:06

Re: Prozessinfos
 
Zitat:

Zitat von silent vapor
Geht das nicht irgendwie in einem Zweizeiler? Das Programm soll so klein wie möglich werden.

Nuja mit einem Zweizeiler nicht ...

Code:
uses TlHelp32,PsAPI

function Execheck(exename:string): string;
var
  aSnapshotHandle: THandle;
  ContinueLoop: BOOL;
  aProcessEntry32: TProcessEntry32;
  handle : thandle;
begin
  aSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  aProcessEntry32.dwSize := Sizeof(aProcessEntry32);
  result := '';
  ContinueLoop := Process32First(aSnapshotHandle, aProcessEntry32);
  handle := 0;
  while integer(ContinueLoop) <> 0 do
    begin
      if (Exename = aProcessEntry32.szExeFile) then
        begin
          Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, aProcessEntry32.th32ProcessID);
          if Handle <> 0 then
            begin
              SetLength(Result, MAX_PATH);
              if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then
                SetLength(Result, StrLen(PChar(Result)))
              else
                Result := '';
              CloseHandle(Handle);
            end;
        end;
      ContinueLoop := Process32Next(aSnapshotHandle, aProcessEntry32);
    end;
  CloseHandle(aSnapshotHandle);
end;

silent vapor 6. Jul 2006 15:24

Re: Prozessinfos
 
Auch wenns kein Zweilzeiler ist, DANKE!


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:54 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz