Solved

Detect whether another program is currently running

Posted on 1998-09-30
7
222 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now