Solved

Executing program with parameters

Posted on 2002-07-07
4
180 Views
Last Modified: 2010-04-04
Hi,

I'm trying to execute an external program with the shellexecute API. The exteranal program needs rather a lot of parameters in order to run correctly however; i.e. c:\dir\progname.exe -para1 -para2 etc.

How can I do this in Delphi? Idealy my program will generate the parameters at run time.

Thanks,

BTW, the external program is xplanet - a you can find more information at http://xplanet.sourceforge.net. I'm attempting to create a small [simple] launcher for it.
0
Comment
Question by:alza
4 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 7135532
Hi alza,

look in the help for samples on  paramcount and paramstr for this

HAGD:O)Bruintje
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 50 total points
ID: 7135759
hello alza, you could try something like this -
add ShellApi to your uses clause

implementation

uses ShellApi

var
ExePath, SendParam: String;
begin

  ExePath := 'C:\Folder\Exe.exe'
  SendParam := Param1+' '+Param2+' '+Param3;

  ShellExecute(Handle,
'open',     // pointer to string that specifies operation to perform
    PChar(ExePath),     // pointer to filename or folder name string
    PChar(SendParam),     // pointer to string that specifies executable-file parameters
    nil,     // pointer to string that specifies default directory
    SW_SHOW      // whether file is shown when opened
   );

end;
0
 

Author Comment

by:alza
ID: 7135800
Hello and thank you to you both.

Slick812;
I've implemented a simple edit box where the parameters can be entered and then assigned to a string (SendParam). This seems to work fine at the moment.

bruintje;
I'm not entirley sure how and where the functions you've mentioned come into it. I've tried using paramstr(0) and this just returns the path of my compiled program...

Thanks,
0
 
LVL 1

Expert Comment

by:herr_apfelschnitt
ID: 7136034
paramstr contains parameters that were used to run the current program, where paramstr(0) (the first one) contains the executable name.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now