Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

Closing a Application

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
snoopy_Spy
Asked:
snoopy_Spy
  • 4
  • 3
  • 2
  • +3
1 Solution
 
MotazCommented:
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
 
tomer_engelCommented:
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
 
snoopy_SpyAuthor Commented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
MotazCommented:
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
 
craig_capelCommented:
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
 
snoopy_SpyAuthor Commented:
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
 
bryan7Commented:
listenning
0
 
craig_capelCommented:
snoopy, does that code work in NT??????????????????
0
 
msediCommented:
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
 
craig_capelCommented:
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
 
snoopy_SpyAuthor Commented:
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
 
msediCommented:
Hello,

sorry, I don't know.
0
 
craig_capelCommented:
works fine on 95 / 98 systems....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now