Solved

Detect whether another program is currently running

Posted on 1998-09-30
7
226 Views
Last Modified: 2010-04-06
I have two Delphi 1.0 applications...Application "A" calls application "B", however, it is vital that application "A" does not call application "B" if application "B" is already running and in memory.   How can I detect from app "A" whether app "B" is currently running and in memory?   I would like to avoid having to use "placemarker" files on the hard disk, you know, app "B" writes a temp file "NOW_RUN.$" and app "A" checks to see if the "NOW_RUN.$" file exists...if it does, then it will not launch app "B"...for this logic could fail if app "B" fails to erase the temp "placemarker" file.  I am looking for a more foolproof method.
0
Comment
Question by:Monroe406
  • 4
  • 3
7 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 70 total points
ID: 1341356
Get the caption of app B and then do the following before executeing app B

var
  H : HWND;
begin
  H := FindWindow(nil, 'TheCaptionOfAppB');
  if H = 0 then begin
    //Execute the program.... e.g ShellExecute()
  end;
end;

Regards,
Viktor Ivanov
0
 

Author Comment

by:Monroe406
ID: 1341357
Thanks!
0
 

Author Comment

by:Monroe406
ID: 1341358
Thanks!

One comment though...  It really isn't the .Caption that I should be looking for, is it?  Is it not the Application.Title string that I should be looking for?   The main .dpr file does not have a .Caption property.
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 10

Expert Comment

by:viktornet
ID: 1341359
The caption of the main form....How many forms do you have in app B??? If there are more then one you can check for all of them or try the Application.Title but I haven't tested that so try it and tell me if it works that way....
0
 

Author Comment

by:Monroe406
ID: 1341360
I have 3 forms in Application "B".   Your code works if I use the Application "A"'s Application.Title property....that's why I made the comment.
0
 

Author Comment

by:Monroe406
ID: 1341361
Whoops!  Typo....my message should have read:

I have 3 forms in Application "B".   Your code works if I use the Application __"B"'s__ Application.Title property....that's why I made the comment.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341362
So it works alright now, right???

//Viktor
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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 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