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 CreateProcess mit Parameterübergabe? (https://www.delphipraxis.net/63781-createprocess-mit-parameteruebergabe.html)

emsländer 22. Feb 2006 20:29


CreateProcess mit Parameterübergabe?
 
Moin,

ich greife mal die Funktion runprocess aus der Code Library auf:

Delphi-Quellcode:
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;
Aufgerufen durch:

Delphi-Quellcode:
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;
Wie kann man hier noch (2) Parameter übergeben?


Gruss

EL

Flocke 22. Feb 2006 20:37

Re: CreateProcess mit Parameterübergabe?
 
CreateProcess bekommt die Kommandozeile als 2. Parameter, also:
Delphi-Quellcode:
...
  if not CreateProcess(nil,
    @Filename[1],
    nil, // <-- HIER
    nil,
    False,
...
Du musst also die Funktion erweitern.

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).

emsländer 22. Feb 2006 21:28

Re: CreateProcess mit Parameterübergabe?
 
Zitat:

Zitat von Flocke
CreateProcess bekommt die Kommandozeile als 2. Parameter, also:
Delphi-Quellcode:
...
  if not CreateProcess(nil,
    @Filename[1],
    nil, // <-- HIER
    nil,
    False,
...
Du musst also die Funktion erweitern.

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).

wenn ich dort, wo Du hinschreibst, erweitere, wird das nix. Bekomme nur den Fehler: inkompatible Typen - String und SecurityAttribute ...


Gruss

EL

turboPASCAL 22. Feb 2006 22:53

Re: CreateProcess mit Parameterübergabe?
 
MSDN-Library durchsuchenCreateProcess

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];

Flocke 23. Feb 2006 06:31

Re: CreateProcess mit Parameterübergabe?
 
Zitat:

Zitat von emsländer
wenn ich dort, wo Du hinschreibst, erweitere, wird das nix. Bekomme nur den Fehler: inkompatible Typen - String und SecurityAttribute ...


Gruss

EL

Sorry, nicht richtig gelesen.

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 18:48 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