Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Close another program from a Delphi program

Posted on 2001-06-13
5
Medium Priority
?
274 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

610 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