Registriert seit: 27. Mai 2005
Ort: Baden
315 Beiträge
Delphi 2007 Enterprise
|
Re: Pfad zur Exe von hProcess
3. Jan 2007, 14:52
Delphi-Quellcode:
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;
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.)
|
|
Zitat
|