Delphi How to get all parameters in one line

application1 starts another application2 with two parameters, for example: (NOTE: application1 is not my program)

application2.exe -d:C:\Program Files\app folder -z:Folder menu\app icons

The problem is that ... the quotes somehow disappeared, so instead of 2 parameters application2 will get 5 parameters

Param1=-d:C:\Program
Param2=Files\app
Param3=folder
Param4=-z:Folder menu\app
Param5=app icons

Is there a way to get all the parameters as a single line?

I tried combining parameters in a loop

for i:=1 to ParamCount do
parameters=parameters+' '+ParamStr(i);

but this is not a good solution, because the path may also contain double or triple spaces for example.

Program files\app   folder\ 

cmd.exe can capture all parameters in% *, but gives incorrect results if the parameter contains special characters, such as ^^ ~ @@ & & & ...

+4
source share
2 answers

Windows API GetCommandLine, .

var
  CmdLine: string;
....
CmdLine := GetCommandLine;

, , ! .

+6

5 2, , 1 , :

application2.exe "-d:C:\Program Files\app folder" "-z:Folder menu\app icons"

:

application2.exe -d:"C:\Program Files\app folder" -z:"Folder menu\app icons"

, 1 , GetCommandLine() , . , -, , , , . , .

+6

All Articles