![]() |
CreateProcess mit Parameterübergabe?
Moin,
ich greife mal die Funktion runprocess aus der Code Library auf:
Delphi-Quellcode:
Aufgerufen durch:
function RunProcess(FileName: string; ShowCmd: DWORD; wait: Boolean; ProcID: PCardinal): Longword;
var StartupInfo: TStartupInfo; ProcessInfo: TProcessInformation; begin FillChar(StartupInfo, SizeOf(StartupInfo), #0); StartupInfo.cb := SizeOf(StartupInfo); StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK; StartupInfo.wShowWindow := ShowCmd; if not CreateProcess(nil, @Filename[1], nil, nil, False, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then Result := WAIT_FAILED else begin if wait = FALSE then begin if ProcID <> nil then ProcID^ := ProcessInfo.dwProcessId; exit; end; WaitForSingleObject(ProcessInfo.hProcess, INFINITE); GetExitCodeProcess(ProcessInfo.hProcess, Result); end; if ProcessInfo.hProcess <> 0 then CloseHandle(ProcessInfo.hProcess); if ProcessInfo.hThread <> 0 then CloseHandle(ProcessInfo.hThread); end;
Delphi-Quellcode:
Wie kann man hier noch (2) Parameter übergeben?
procedure TForm1.Button1Click(Sender: TObject);
var ProcID: Cardinal; begin if OpenDialog1.Execute then RunProcess(OpenDialog1.FileName, SW_MINIMIZE, TRUE, ProcID); Messagebox(0, 'fertig', @OpenDialog1.Filename[1], 0); end; Gruss EL |
Re: CreateProcess mit Parameterübergabe?
CreateProcess bekommt die Kommandozeile als 2. Parameter, also:
Delphi-Quellcode:
Du musst also die Funktion erweitern.
...
if not CreateProcess(nil, @Filename[1], nil, // <-- HIER nil, False, ... Bedenke allerdings, dass es sich um die komplette Kommandozeile handeln sollte, also inkl. Filename (im Grunde so, wie man es auf der Kommandozeile hinschreiben würde). |
Re: CreateProcess mit Parameterübergabe?
Zitat:
Gruss EL |
Re: CreateProcess mit Parameterübergabe?
![]()
Code:
BOOL [b]CreateProcess[/b][b]([/b]
[color=#ff0000]LPCTSTR lpApplicationName[/color], [color=#00A000]// pointer to name of executable module[/color] [color=#ff0000]LPTSTR lpCommandLine[/color], [color=#00A000]// pointer to command line string[/color] LPSECURITY_ATTRIBUTES lpProcessAttributes, [color=#00A000]// pointer to process security attributes[/color] LPSECURITY_ATTRIBUTES lpThreadAttributes, [color=#00A000]// pointer to thread security attributes[/color] BOOL bInheritHandles, [color=#00A000]// handle inheritance flag[/color] DWORD dwCreationFlags, [color=#00A000]// creation flags[/color] LPVOID lpEnvironment, [color=#00A000]// pointer to new environment block[/color] LPCTSTR lpCurrentDirectory, [color=#00A000]// pointer to current directory name[/color] LPSTARTUPINFO lpStartupInfo, [color=#00A000]// pointer to STARTUPINFO[/color] LPPROCESS_INFORMATION lpProcessInformation [color=#00A000]// pointer to PROCESS_INFORMATION[/color] [b])[/b]; |
Re: CreateProcess mit Parameterübergabe?
Zitat:
In diesem Fall kannst du einfach die komplette Kommandozeile als "FileName" angeben, also einfach die Parameter nach einem Leerzeichen an die Echse dranhängen. Aber: wenn im Pfad Leerzeichen sind, dann musst du den Dateinamen in doppelte Anführungszeichen setzen. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:38 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