We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

How do I put in parameter in a shellexecute?

QC20N
QC20N asked
on
Medium Priority
318 Views
Last Modified: 2013-11-23
Comment
Watch Question

MerijnBSr. Software Engineer
CERTIFIED EXPERT

Commented:
Just add the parameters after the executable:


procedure TForm1.Button1Click(Sender: TObject);
var fileName: string;
    Params: string;
begin
  fileName := IncludeTrailingBackSlash(GetEnvironmentVariable('ProgramFiles')) + 'Internet Explorer\iexplore.exe';
  Params := '"paramter 1" "paramter 2" anotherparameter';
  ShellExecute(0, 'open', PChar(fileName + ' ' + Params), nil, nil, SW_SHOWNORMAL);
end;

Open in new window

uses ShellApi;

var
  vAction: String;
  vFileName:String;
  vParams: String;
  vPath: String;

  vAction := 'open';
  vFileName := 'c:\application.exe';
  vParams := 'param1 param2';
  vPath := ExtractFilePath(vFileName);

ShellExecute(0, PChar(vAction), PChar(vFilename), PChar(vParams), PChar(cPath), SW_SHOWNORMAL);

if Params are:
/v /p
then
vParams := '/v /p';

 

lol too late

Author

Commented:
You see guys. I have tried that, but with no result. It dosen't start.

If I don't have any params it starts.


  action := 'open';
  filename := includeTrailingbackslash(getenvironmentvariable('programfiles'))+ 'DameWare Development\DameWare Mini Remote Control\dwrcc.exe';
  params := '-c: -a:1'; // -m:' + listbox1.Items.Strings[listbox1.itemindex];
  ShellExecute(0, 'open', PChar(fileName + ' ' + Params), nil, nil, SW_SHOWNORMAL);

Open in new window

No it's wrong, "Params" are separated from file name.
this is wrong:
ShellExecute(0, 'open', PChar(fileName + ' ' + Params), nil, nil, SW_SHOWNORMAL);

It should be:
ShellExecute(0, 'open', PChar(fileName), PChar(Params), nil, SW_SHOWNORMAL);

PS you don't heve set up action variable if you are using "open" parameter direct in shellexecute

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
MerijnBSr. Software Engineer
CERTIFIED EXPERT

Commented:
try:
  action := 'open';
  filename := includeTrailingbackslash(getenvironmentvariable('programfiles'))+ 'DameWare Development\DameWare Mini Remote Control\dwrcc.exe';
  params := '-c: -a:1'; // -m:' + listbox1.Items.Strings[listbox1.itemindex];
  ShellExecute(0, 'open', PChar(fileName), PChar(params), nil, SW_SHOWNORMAL);

Open in new window

MerijnBSr. Software Engineer
CERTIFIED EXPERT

Commented:
ok, something strange happened here, I submitted this 25 minutes ago???

Author

Commented:
I can give you 50 point, if you want, for your effort.
MerijnBSr. Software Engineer
CERTIFIED EXPERT

Commented:
Don't worry :)
Geert GOracle dba
CERTIFIED EXPERT
Top Expert 2009

Commented:
Be happy

Author

Commented:
I am. :D
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.