Solved

Detect whether another program is currently running

Posted on 1998-09-30
7
220 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

22 Experts available now in Live!

Get 1:1 Help Now