Solved

Easy Question: Executing an ExternalProgram

Posted on 1998-10-31
9
134 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 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

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…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 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