Solved

closing other running applications

Posted on 1999-01-12
9
137 Views
Last Modified: 2010-04-06
How can I close/kill/interrupt a running application/dll/... from my delphi application?

SkAtAn
0
Comment
Question by:skatan187
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1356161
Send it a WM_QUIT message or use TerminateProcess...
0
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1356162
you use sendmessage or postmessage with the message WM_QUIT or WM_CLOSE (WM_CLOSE is better because it forces the window to close).,,,,

here is an example...


var
  h : HWND;
begin
  h := FindWindow(nil, 'Notepad - Untitled');
  if h <> 0 then begin
    SendMessage(h, WM_CLOSE, 0, 0);
    ShowMessage('Well, we just kill notepad :)');
  end else ShowMessage('There is no such a window at the moment');
end;

Hope this helps...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1356163
If you want the program to ask the user if he/she wants to save the currently opened file, you have to send a WM_CLOSE to the main window.
If you don't like this, send a WM_QUIT either to the main window or (and that is what I'm normally doing) to the main thread by using PostThreadMessage(tid,WM_QUIT,0,0);
You can use TerminateProcess, too. But that's quite ugly, because it does NOT perform a CLEAN program shutdown. (Read the documentation of TerminateProcess)

Regards, Madshi.
0
 
LVL 1

Author Comment

by:skatan187
ID: 1356164
Ok this worked.. is there alse a way to get all running application (titles) in a tstrings/list/array ?


SkAtan
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 20

Expert Comment

by:Madshi
ID: 1356165
If you look at this question (hurry, it's still open in the moment)

http://www.experts-exchange.com/topics/comp/lang/delphi/Q.10117362

you'll find a solution for that for win95/98.

If you need it to run under NT4, too, and you have Delphi 4, you can download my "enumStuff" unit from my homepage "http://www.madshi.com" in the "sources" section. This unit gives you some handy functions to enumerate all running applications, but it runs only under Delphi 4.

Regards, Madshi.
0
 
LVL 1

Author Comment

by:skatan187
ID: 1356166
ok thx alot.. Madshi
and viktornet for the correct answer :-)

SkAtAn
0
 
LVL 1

Author Comment

by:skatan187
ID: 1356167
>>

You can use TerminateProcess, too. But that's quite ugly, because it does NOT perform a CLEAN program shutdown. (Read the documentation of TerminateProcess)

<<

jep.. this is what I need.. the program ABSOLUTLY MUST SHUT DOWN without doing furter actions.. I already accepted this question.. but ofcourse you may gimme a sample for this.. (probebly I'll find it myself.. oh well! :-)

SkAtan


0
 
LVL 20

Expert Comment

by:Madshi
ID: 1356168
Use this function. But you must give in the processID of the process you want to shut down. You get the processID from both the sources of the other question I mentioned or from the functions in my "enumStuff" unit.

procedure ShutUp_Process(processID: cardinal);
var c1 : cardinal;
begin
  c1:=OpenProcess(PROCESS_ALL_ACCESS,false,pid);
  if c1<>0 then
    try
      TerminateProcess(c1,0);
    finally CloseHandle(c1) end;
end;

Regards, Madshi.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1356169
you can use EnumWindows() to get all windows in a TStringList or Listbox or whatever..if you need an example let me know.... yeah Madshi is right.. TerminateProcess() is another way to shut down a process...

Madshi, you've given your procedure a nice name :))

-Viktor
--Ivanov
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

19 Experts available now in Live!

Get 1:1 Help Now