Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Delphi 10 Run a program with parameters (shellExecute)



Permlink Replies: 2 - Last Post: Apr 19, 2017 11:35 PM Last Post By: Andreas Schütz
Andreas Schütz

Posts: 2
Registered: 5/17/07
Delphi 10 Run a program with parameters (shellExecute)
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 19, 2017 7:21 AM
Hello

I have a delphi program where I have to start within Delphi a program with some parameters.
Until now I do it like this and it is working fine:

ShellExecute(0, 'open', 'C:\Catia\V5R20W7X\win_b64\code\bin\CATSTART.exe', '-env UserEnvironment64Bit -direnv "C:\ProgramData\Catia\V5R20W7X\CATEnv" -nowindow', nil, SW_ShowNormal);

But I would like to use some variables instead, for excample for the path. But until now I did not find any way how to do that. I tried a lot but nothings works.
Can anyone give me a hint how to do this? I could not solve the problem with all the quotation marks.
I'm open for any solution.

kind regards

Andreas
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Delphi 10 Run a program with parameters (shellExecute)
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 19, 2017 9:21 AM   in response to: Andreas Schütz in response to: Andreas Schütz
Andreas wrote:

I have a delphi program where I have to start within Delphi a program
with some parameters. Until now I do it like this and it is working
fine:

You should be using CreateProcess() for that, instead of ShelllExecute().

But I would like to use some variables instead, for excample for the
path. But until now I did not find any way how to do that. I tried a
lot but nothings works.

What is the actual problem you are having with it? Using string variables
for this is very easy, eg:

var
  ExeFile: string;
  Env, DirEnv: string;
  Params: string;
begin
  ExeFile := ...; // 'C:\Catia\V5R20W7X\win_b64\code\bin\CATSTART.exe'
  Env := ...; // 'UserEnvironment64Bit'
  DirEnv := ...; // 'C:\ProgramData\Catia\V5R20W7X\CATEnv'
 
  if Pos(' ', DirEnv) <> 0 then
    DirEnv := AnsiQuotedStr(DirEnv, #34);
 
  Params := '-env ' + Env + ' -direnv ' + DirEnv + ' -nowindow';
  // or:
  // Params := Format('-env %s -direnv %s -nowindow', [Env, DirEnv]);
 
  ShellExecute(0, 'open', PChar(ExeFile), PChar(Params), nil, SW_ShowNormal);
end;


--
Remy Lebeau (TeamB)
Andreas Schütz

Posts: 2
Registered: 5/17/07
Re: Delphi 10 Run a program with parameters (shellExecute)
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 19, 2017 11:35 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hello

thank you for the help and the tip with CreateProcess. I have tried it and it works better for me...

Andreas


Remy Lebeau (TeamB) wrote:
Andreas wrote:

I have a delphi program where I have to start within Delphi a program
with some parameters. Until now I do it like this and it is working
fine:

You should be using CreateProcess() for that, instead of ShelllExecute().

But I would like to use some variables instead, for excample for the
path. But until now I did not find any way how to do that. I tried a
lot but nothings works.

What is the actual problem you are having with it? Using string variables
for this is very easy, eg:

var
  ExeFile: string;
  Env, DirEnv: string;
  Params: string;
begin
  ExeFile := ...; // 'C:\Catia\V5R20W7X\win_b64\code\bin\CATSTART.exe'
  Env := ...; // 'UserEnvironment64Bit'
  DirEnv := ...; // 'C:\ProgramData\Catia\V5R20W7X\CATEnv'
 
  if Pos(' ', DirEnv) <> 0 then
    DirEnv := AnsiQuotedStr(DirEnv, #34);
 
  Params := '-env ' + Env + ' -direnv ' + DirEnv + ' -nowindow';
  // or:
  // Params := Format('-env %s -direnv %s -nowindow', [Env, DirEnv]);
 
  ShellExecute(0, 'open', PChar(ExeFile), PChar(Params), nil, SW_ShowNormal);
end;


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02