Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ShellExecute - close an application

2,765 views
Skip to first unread message

Alan

unread,
May 17, 2006, 11:10:04 PM5/17/06
to
Can I use ShellExecute to close down an application like Notepad ?


Rob Kennedy

unread,
May 17, 2006, 11:35:16 PM5/17/06
to
Alan wrote:
> Can I use ShellExecute to close down an application like Notepad ?

Only if you use it to execute a program that knows how to close programs.

Perhaps you want to read the following article.

What can I do with the HINSTANCE returned by the ShellExecute function?
http://blogs.msdn.com/oldnewthing/archive/2006/05/05/590749.aspx

--
Rob

Alan

unread,
May 17, 2006, 11:42:41 PM5/17/06
to
What I want is to shut down some processes for example notepad, windows
explorer.
What other API can I do that?

"Rob Kennedy" <m...@privacy.net> wrote in message
news:446beb6e$1...@newsgroups.borland.com...

Rob Kennedy

unread,
May 18, 2006, 12:21:32 AM5/18/06
to
Alan wrote:
> What I want is to shut down some processes for example notepad, windows
> explorer.
> What other API can I do that?

Well, TerminateProcess does a pretty thorough job. Search the newsgroup
archives for discussions about that function and various alternatives.
You're not the first person to ask how to close a program, so you should
be able to find lots of other messages on the topic.

--
Rob

Alan

unread,
May 18, 2006, 1:58:22 AM5/18/06
to
Sorry, I went to the Borland's Delphi newsgroup page but cannot find archive
ones?

"Rob Kennedy" <m...@privacy.net> wrote in message

news:446bf646$1...@newsgroups.borland.com...

Rob Kennedy

unread,
May 18, 2006, 2:14:34 AM5/18/06
to
Alan wrote:
> Sorry, I went to the Borland's Delphi newsgroup page but cannot find archive
> ones?

http://groups.google.com/

See also:

How can I search the newsgroup archives?
http://www.cs.wisc.edu/~rkennedy/mozilla-search

--
Rob

Andrew Jameson

unread,
May 18, 2006, 4:01:18 AM5/18/06
to
ShellExecute ? ... no, simply post either WM_QUIT or WM_CLOSE if you want
the application to use the save changes dialog before it closes :

procedure TForm1.Button1Click(Sender: TObject);
var
aHWnd : HWND;
begin
aHWnd := FindWindow('Notepad', nil);
if (aHWnd <> 0) then
PostMessage(aHWnd, WM_QUIT, 0, 0);
// or ...
//PostMessage(aHWnd, WM_CLOSE, 0, 0);
end;

Andrew

"Alan" <alanplt...@yahoo.com.au> wrote in message
news:446be589$1...@newsgroups.borland.com...

Arab Ibrahim

unread,
May 20, 2006, 4:40:27 AM5/20/06
to

"Alan" <alanplt...@yahoo.com.au> wrote:
>Can I use ShellExecute to close down an application like Notepad ?
>
>

Sure you can

Create temporary .bat file using TStringList (create, add(..), savetofile(your bat file) with following content

TASKKILL /IM notepad.exe
del "short path to this .bat file here"
close

Then run this using shellexecute(GetDesktopWindow,.........SW_HIDE);

Enjoy!

Arab Ibrahim

0 new messages