Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Easy Question: Executing an ExternalProgram

Posted on 1998-10-31
9
Medium Priority
?
141 Views
Last Modified: 2010-04-06
If I have a button and on-click I wanted it to launch Wordpad, what function do I call?
0
Comment
Question by:John_C
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 180 total points
ID: 1345156
Hi John_C,

you can use  shellexecute. but then it uses the default program. So if word is installed I guess it starts up Word.

procedure TForm1.Button1Click(Sender: TObject);
var temp : string  ;
begin
Temp:='c:\log.doc';
ShellExecute(Application.Handle,'open',PChar(Temp),nil,nil,SW_NORMAL);
end;

you can use createprocess for opening wordpad :

read this article : http://www.delumpa.com/tips/wapi/wapi4.htm


Regards, Zif.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1345157
Hello,
or you could use the following:

procedure TForm1.Button1Click(Sender: TObject);
begin
 ShellExecute
(Handle, NIL,'C:\ProgramFiles\Accessories\WORDPAD.EXE', NIL, NIL, sw_ShowNormal);
end;
ps..if you use shellexecute you need to add "ShellApi" to your "uses" clause.
InThe
0
 
LVL 17

Expert Comment

by:inthe
ID: 1345158
Hello,
or you could use the following:

procedure TForm1.Button1Click(Sender: TObject);
begin
 ShellExecute
(Handle, NIL,'C:\ProgramFiles\Accessories\WORDPAD.EXE', NIL, NIL, sw_ShowNormal);
end;
ps..if you use shellexecute you need to add "ShellApi" to your "uses" clause.
InThe
0
Industry Leaders: 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!

 
LVL 8

Expert Comment

by:ZifNab
ID: 1345159
inthe, correct, but if you use it your way, you need to be sure it is installed in that directory. Better would be to first search the directory in which wordpad resides.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1345160
john c
yes this is good idea from zifnab.you can never be really sure of where someone has installed their progs.
InThe
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1345161
Hello guys.. If you just put Wordpad.exe as a path it will launch it by itself if it's in the system... It usually looks in the system and if it finds it there then it will excute it... Same thing about Notepad.exe =) It works here :-)

Cheers,
Viktor
0
 

Author Comment

by:John_C
ID: 1345162
Thank you for the answer.  While it did help me out, your solution really would have launched whatever was associated with a .doc file.  I would have given you an A had you simply presented me a solution that directly answered my question.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1345163
I'm just not sure who you are talking to, but anyway... Hope you got it working =)

Cheers,
Viktor
0
 

Expert Comment

by:mami
ID: 1345164
procedure TForm1.Button1Click(Sender: TObject);
// This execute the program notepad.exe that is in the path.
begin
        winexec('notepad.exe',1);
end;

procedure TForm1.Button2Click(Sender: TObject);
// Here we execte a program that is'n in the path.
begin
        winexec('c:\mypath\myprogram.exe',1);
end;

For more information see the function winexec and shellexecute in the windows's api win32.hlp
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

886 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