Solved

Close another program from a Delphi program

Posted on 2001-06-13
5
270 Views
Last Modified: 2010-04-06
My problem is the following:

On a Windows NT server I have a program scheduled to run once a day. This program always ends with a message box, saying that the operations was successful or not. I must click OK to close this message box.
So, when I don't look at my server for ten days, there are ten message boxes on the screen. The Windows NT task manager also shows ten programs open.

I now think of a solution with a Delphi program that closes this particular program on the server. I can schedule it i.e. one hour after the scheduling time of the other program. The only thing I like to know is: can I close another program from within my Delphi program?

Thanks,
JDN
0
Comment
Question by:JDN
[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
5 Comments
 
LVL 8

Accepted Solution

by:
Cesario earned 50 total points
ID: 6186221
Hi JDN,

yes you can do it ;-)

You can send the application a WM_QUIT message:

PostMessage(FindWindow(Nil, 'window caption'), WM_QUIT, 0, 0);

Where "window caption" is the caption of the window that you
are sending the message to.

Best Regards

Cesario
0
 
LVL 4

Expert Comment

by:Colin_Dawson
ID: 6186250
How about something like this....

Procedure CloseProg;
Var
  MyHandle : THandle;
Begin
  MyHandle := FindWindow( null, 'Messagebox Title' );
  If MyHandle <> null Then
  Begin
    PostMessage( MyHandle, WM_Close, 0, 0 );
  End;
End;

I have no idea if this code will work, but it might be worth a try :-)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6186814
Please use WM_CLOSE. WM_QUIT is not documented to work when being sent to a window, instead it should be sent to a *thread*, and WM_CLOSE is cleaner anyway...

Regards, Madshi.
0
 
LVL 4

Expert Comment

by:Colin_Dawson
ID: 6187810
aaarrrggghhh you beat me by 4 minutes.  :-)
0
 
LVL 1

Author Comment

by:JDN
ID: 6189676
Thank you all for your help.
And sorry Colin, only one can be the winner...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 119
DBGrid or StringGrid ? 6 131
Can Live bindings change TGrid Cell Colour ? 1 57
Error when I try to post by IdHttp, error 500 - Help 2 18
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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