Solved

Closing a Application

Posted on 2000-04-18
13
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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