Solved

Closing a Application

Posted on 2000-04-18
13
148 Views
Last Modified: 2010-04-04
How can i close a application, when it doesn't response. I have written a little prog, which checks every minute, if the application is alive, and when th eapplication didn't answer, i would like to kick it, and start again !
0
Comment
Question by:snoopy_Spy
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 2726607
What did you mean exactly?
if you mean that some application stay as a gaurd for another appliction I can help you.

You can chech the other application existence such as:

var
  H: hwnd;
begin
  H:= FindWindow('TfmMain', 'Printer reports');

  if H = 0 then
    ShellExecute(handle, 'open',
      PChar(ExtractFilePath(ParamStr(0)) + 'Traffic.exe'),
        nil, nil, sw_ShowMinimized);

This code exists in a timer and it checks if the other application exists or not (TfmMain) if it didn't exists it will run it.

The parameters:

  FindWindow(MainWindowsClassName, Caption_of_Main_Window);

Motaz
0
 
LVL 1

Expert Comment

by:tomer_engel
ID: 2726620
what motaz  suggested is very good.

you can implement another approch--the original application can send messages(acostomed message)to athread of  his (each minute).the thread "knows" that  it should get messages every 1 min. if it doesnt get it apply the close procedure,and restart the     applciation
0
 

Author Comment

by:snoopy_Spy
ID: 2726687
I don't need the routine for checking if the application is alive ! - This works allready fine.
I need to shut down the application if it hangs !
Sending the application a WM_CLOSE or something else doesn't work - only closeing it with the Windows NT TaskManager works ! - So how can i close the Process from my programm ?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 7

Expert Comment

by:Motaz
ID: 2726710
I think the best way is to prevent your application from hangin, use Try except in the code that might cause that hanging.

You can post your code here to see what is the problem.

Hanging is a problem in your code.

Motaz
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2726770
var
wnd : hwnd;
ProcessID,cpid : Cardinal;
begin
wnd:=form1.handle; //handle of window  (in this case findwindow(nil,'title of your program')
ProcessID := GetWindowThreadProcessID(wnd,@cpid);
TerminateProcess(OpenProcess(PROCESS_TERMINATE,false,cpid),1);
end;

and that will simulate alt ctrl and del on it.....

Craig C.
0
 

Author Comment

by:snoopy_Spy
ID: 2726772
This isn't my programm !
I only wrote the programm which checks, if the application is working fine. But when the application hangs, i would like to close the task or the process !
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2729010
listenning
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2729033
snoopy, does that code work in NT??????????????????
0
 
LVL 1

Expert Comment

by:msedi
ID: 2731004
Hello,

First I think it's not a good way to call TerminateThread or TerminateProcess. These functions are very rude and will kick out your app without freeing memory or so. In this case you will get some day a out of memory error?
For your message timeout: There is a windows message something like WM_..._TIMEOUT, but I don't know the exact message name. This message is sent from windows to the app in order to check whether the app is still ok or not. That's what you will see in your task list in WinNT if it's responding or not

Another question: Why will this application hang so often?

Good luck, Martin
0
 
LVL 2

Accepted Solution

by:
craig_capel earned 50 total points
ID: 2731088
msedi, if an app has hung, it can not release the memory back to windows anyhow... Terminating it from NT does that to put back the memory?... I don't see how...

There is no other way, at least i don't think ....
0
 

Author Comment

by:snoopy_Spy
ID: 2732988
Yes it works !
Thanxs
But, do you know if this works under Win9X or Win2K ? I don't use them, but i would like to know it ...
0
 
LVL 1

Expert Comment

by:msedi
ID: 2733690
Hello,

sorry, I don't know.
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2733895
works fine on 95 / 98 systems....
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

825 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