Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

Detect whether another program is currently running

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
Monroe406
Asked:
Monroe406
  • 4
  • 3
1 Solution
 
viktornetCommented:
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
 
Monroe406Author Commented:
Thanks!
0
 
Monroe406Author Commented:
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
Independent Software Vendors: 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!

 
viktornetCommented:
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
 
Monroe406Author Commented:
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
 
Monroe406Author Commented:
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
 
viktornetCommented:
So it works alright now, right???

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

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now