• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

Running programs

Hi!

Maybe it's an easy question, but anyway... how can i run a program when my application starts?

That program could be a com, exe or a batch (.bat) file.

Thank you
0
janez
Asked:
janez
  • 2
  • 2
  • 2
  • +2
1 Solution
 
cobramaniaCommented:
Use  WinExec for simple execution:

procedure TForm1.Button1Click(Sender: TObject);
begin
     if (WinExec('C:\Progra~1\GrIP\GripInit.exe', SW_SHOWNORMAL)<32) then
        MessageDlg('You dont have GripInit.exe',mtError,[mbOK],0);
end;

Change to Form Show event if you want the program executed when your program run.

Hope this helps :)
0
 
janezAuthor Commented:
For cobramania:

Hi! Your answer is excellent and i'll evaluate it, but i'd like to ask you something else. How can I run a program with patameters, for example: "arj.exe x archive.arj" ?

Thank you
0
 
yingkitCommented:
Hi, try the following:

uses shellapi;
.......
procedure TForm1.Button1Click(Sender: TObject);
begin
     ShellExecute(0, 'open', PChar(arj.exe), pchar('x archive.arj'), nil, SW_NORMAL);
end;
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
janezAuthor Commented:
Sorry yingkit, i have to reject your answer, because i promised to cobramania to evaluate his answer. Really sorry again!

0
 
cobramaniaCommented:
Hi, since i thought you don't need any paramater so i pasted the previous code....
Here's the complete code of mine with the parameter:

procedure TForm1.Button1Click(Sender: TObject);
begin
     if (WinExec('C:\Progra~1\GrIP\GripInit.exe -ge -ke', SW_SHOWNORMAL)<32) then
        MessageDlg('You dont have GripInit.exe',mtError,[mbOK],0);
end;

take a look at the "-ge" and "-ke" parameters

Hope this helps :)
0
 
titzCommented:
hi,
you can do the same with CREATEPROCESS.
if wanted i can give you an example.

cheers
titz
0
 
zeno_rummlerCommented:
I don't know what operating system you are programming for.
The WinExec function is available just for compatibility to the 16-bit systems!!
To start a program, use - like mentiones before - ShellExecute oder
CrateProcess.
I found out, that ShellExecute is more stabel, when you change the OS.
Running at win9x, Win NT 4.0 won't start the programm and creates an ACCESS_DENIED ERROR
0
 
zeno_rummlerCommented:
Sorry, I forgot:
The parameters for these function are described in
win32.hlp of delhi3

:)

Zeno
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now