![]() |
Pfad zur Exe von hProcess
Hi,
Also den Dateinamen eines Prozesses habe ich jetzt herausgefunden... Aber ich bekomme halt nur sowas wie delphi32.exe... Ich bräuchte aber den ganzen Pfad.. :| Kann ich den irgendwie bekommen? Gruß Neutral General |
Re: Pfad zur Exe von hProcess
das geht mit Module32First und szExeName (oder so)
funktioniert laut NicoDE aber nicht auf allen VMs Oder meinst du nun wirklich einen Prozesshandle (hProcess) und nicht die ProzessId? Wie hast du denn vom Handle her den Dateinamen erhalten? |
Re: Pfad zur Exe von hProcess
mittels TModuleEntry32 kannst du den Pfad auslesen (erstes Modul ist immer die *.exe Datei)
Delphi-Quellcode:
uses TlHelp32;
const ProcessId = 1684; var ModuleEntry: TModuleEntry32; hModuleEntry: THandle; sPfad: String; begin hModuleEntry := CreateToolHelp32Snapshot(TH32CS_SNAPMODULE, ProcessId); ModuleEntry.dwSize := SizeOf(TModuleEntry32); Module32First(hModuleEntry, ModuleEntry); sPfad := ModuleEntry.szExePath; CloseHandle(hModuleEntry); |
Re: Pfad zur Exe von hProcess
Habe diese Funktion aus einer anderen aus der DP abgeleitet:
Delphi-Quellcode:
Habe jetzt mal TModuleEntry32 genommen statt TProcessEntry32... Aber da bekomme ich nix zurück...
function GetProcessExename(hProcess: THandle): String;
var hProcSnap: THandle; pe32: TProcessEntry32; begin hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0); if hProcSnap <> INVALID_HANDLE_VALUE then begin pe32.dwSize := SizeOf(TProcessEntry32); if Process32First(hProcSnap, pe32) = true then begin while Process32Next(hProcSnap, pe32) = true do begin if pe32.th32ProcessID = hProcess then begin Result := pe32.szExeFile; exit; end; end; end; CloseHandle(hProcSnap); end; end; Die ID bekomm ich so:
Delphi-Quellcode:
Aber wie gesagt... Es funktioniert noch nicht so wies soll :mrgreen:
GetWindowThreadProcessId(wnd,hProcess);
Gruß Neutral General |
Re: Pfad zur Exe von hProcess
wie wäre es damit?
Delphi-Quellcode:
Edit: ah ne, diese funktion ließt nur aus dem eigenen Prozess aus
function GetProcessExeName(hProcess: THandle): String;
var ModuleEntry: TModuleEntry32; hModuleEntry: THandle; ProcessId: Cardinal; begin if hProcess = INVALID_HANDLE_VALUE then Exit; ProcessId := GetWindowThreadProcessId(hProcess); hModuleEntry := CreateToolHelp32Snapshot(TH32CS_SNAPMODULE, ProcessId); ModuleEntry.dwSize := SizeOf(TModuleEntry32); Module32First(hModuleEntry, ModuleEntry); Result := MOduleEntry.szExePath; CloseHandle(hModuleEntry); end; |
Re: Pfad zur Exe von hProcess
Delphi-Quellcode:
So, das funktioniert bei mir, aber halt nur mit PsApi und GetModuleFileNameEx (d.h. Requires Windows Vista, Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0.)
uses PsApi;
function GetProcessExeName(hProcess: THandle): String; var lpBuffer: array[0..MAX_PATH -1] of Char; begin ZeroMemory(@lpBuffer, SizeOf(lpBuffer)); GetModuleFileNameEx(hProcess, 0, lpBuffer, SizeOf(lpBuffer)); Result := String(lpBuffer); end; procedure TForm1.FormCreate(Sender: TObject); var lpStartupInfo: TStartupInfo; lpProcessInformation: TProcessInformation; begin ZeroMemory(@lpStartupInfo, sizeof(TStartupInfo)); lpStartupInfo.cb := sizeof(TStartupInfo); lpStartupInfo.dwFlags := STARTF_USESHOWWINDOW; lpStartupInfo.wShowWindow := SW_SHOW; ZeroMemory(@lpProcessInformation, sizeof(TProcessInformation)); CreateProcess(nil, 'notepad.exe', nil, nil, False, CREATE_NEW_CONSOLE, nil, nil, lpStartupInfo, lpProcessInformation); Application.MessageBox(PAnsiChar(GetProcessExeName(lpprocessinformation.hProcess)), 'Path', MB_ICONINFORMATION); TerminateProcess(lpProcessInformation.hProcess, 0); Application.Terminate; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:11 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz