Solved

Easy Question: Executing an ExternalProgram

Posted on 1998-10-31
9
133 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
Comment Utility
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
Comment Utility
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
Comment Utility
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 8

Expert Comment

by:ZifNab
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 17

Expert Comment

by:inthe
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I'm just not sure who you are talking to, but anyway... Hope you got it working =)

Cheers,
Viktor
0
 

Expert Comment

by:mami
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 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…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

13 Experts available now in Live!

Get 1:1 Help Now