Solved

Easy Question: Executing an ExternalProgram

Posted on 1998-10-31
9
136 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 60 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
Technology Partners: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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