Solved

Easy Question: Executing an ExternalProgram

Posted on 1998-10-31
9
138 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month5 days, 16 hours left to enroll

627 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