Solved

Detect whether another program is currently running

Posted on 1998-09-30
7
225 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
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

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
Best Firemonkey component pack 1 119
find a node in VST 2 70
JAudiorecorder record freezing the app 29 74
Delphi problems to abort a printjob 9 24
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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