Solved

Running programs

Posted on 2000-02-26
8
168 Views
Last Modified: 2010-04-04
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
Comment
Question by:janez
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 1

Expert Comment

by:cobramania
ID: 2561825
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
 

Author Comment

by:janez
ID: 2562252
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
 

Expert Comment

by:yingkit
ID: 2562322
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
 

Author Comment

by:janez
ID: 2562393
Sorry yingkit, i have to reject your answer, because i promised to cobramania to evaluate his answer. Really sorry again!

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Accepted Solution

by:
cobramania earned 30 total points
ID: 2562548
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
 
LVL 1

Expert Comment

by:titz
ID: 2573778
hi,
you can do the same with CREATEPROCESS.
if wanted i can give you an example.

cheers
titz
0
 

Expert Comment

by:zeno_rummler
ID: 2596587
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
 

Expert Comment

by:zeno_rummler
ID: 2596595
Sorry, I forgot:
The parameters for these function are described in
win32.hlp of delhi3

:)

Zeno
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IExtractImage Delphi 14 201
How to use Hashing sha1 in Delphi 2010 4 199
How to fill array with TArray.Create? 14 79
Working with hours 3 46
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

23 Experts available now in Live!

Get 1:1 Help Now