Solved

Simple Easy, Check For Instance Of Running Program

Posted on 2000-04-11
11
298 Views
Last Modified: 2010-04-04
Hi Folks, sometime ago i had a bit of code that created an "atom" and when a program ran, it looked to see if it was already in memory if it was my delphi program would not run until it closed it down..... it was only a few lines long.....

I don't suppose anyone here has the code, or an alternative solution to this? :)

Thanks....

Craig C.
0
Comment
Question by:craig_capel
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2703990
Hi Craig,

it is AddAtom, FindAtom and DeleteAtom in the Win32 API.

Ciao, Mike
0
 
LVL 6

Expert Comment

by:edey
ID: 2704183
Though Atoms are used for this purpose, it isn't generally recomended as the size of the atom table (and the atoms) is limited, one of those "provided for compatibility" things.  This is a pretty commonly asked question, though, so heres a previously asked question (should *always* try the search engine first :) on semaphores (found searching for "one instance"):

http://www1.experts-exchange.com/bin/ShowQ?qid=10121069&search=

GL
Mike
0
 
LVL 2

Accepted Solution

by:
CalvinDay earned 35 total points
ID: 2704463
I use something like this:

program xPrint;

uses
  Hide1,
  Hide2,
  Windows,
  Forms,
  uPrint in 'uPrint.pas' {fPrint},
  uAbout in 'uAbout.pas' {fAbout};

{$R *.RES}

begin
  CreateMutex(nil,false,'xPrint');
  if GetLastError=ERROR_ALREADY_EXISTS then
    begin
    SendMessage(HWND_BROADCAST,RegisterWindowMessage('xPrint'),0,0);
    Halt(0);
    end;

  Application.Initialize;
  Application.Title := 'xPrint';
  Application.CreateForm(TfPrint, fPrint);
  Application.Run;
end.


You can use the sendmessage to alert the other instance to wake up.

0
 
LVL 2

Author Comment

by:craig_capel
ID: 2704581
edey, although true, how would you get easy points?.....

ok just testing out a couple of your suggestions... Thanks all, brb....
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2708040
sorry for the delay.... recovering from a hangover.... :)

But your code worked great..... Thanks a lot, sorry for the lack of points....
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 10

Expert Comment

by:Lischke
ID: 2709208
Hi Craig,

please formulate your future questions a bit more carefully. I honestly thought you need to work with atoms not just to prevent your application from running twice. Otherwise I had given you an elegant solution. The broadcast thingy is really bad as it needs on some machine several seconds to return. For a precise question you can get really professional answers. Consider this...

Ciao, Mike
0
 
LVL 2

Expert Comment

by:CalvinDay
ID: 2709274
Mike,

I agree with your statement about the broadcast. Setting up and trapping the broadcast is really a pain.

If you have a more elegant (hopefully simple) soluton to this please let us know. I will post a 50 point question for it.

Please post it here.
0
 
LVL 2

Expert Comment

by:CalvinDay
ID: 2709332
Mike,

I agree with your statement about the broadcast. Setting up and trapping the broadcast is really a pain.

If you have a more elegant (hopefully simple) soluton to this please let us know. I will post a 50 point question for it.

Please post it here.
0
 
LVL 2

Expert Comment

by:CalvinDay
ID: 2709336
Don't ya hate that.
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2709375
I don't suppose anyone here has the code, or an alternative solution to this? :)

Lischke... Sorry, but i don't want to sound rude, but i did put in my very first comment.... "I don't suppose anyone here has the code, or an alternative solution to this? :)"

An alternative such as Calvin gave worked great for me.... yeah i just knew about the attoms.... i did not care how i did it, i was thinking about writing a file to disk or something, but thats BAD programming, then i thought about DDE, in the end i would just ask about code i had seen before... sorry :(

Thanks for your help again guys....

Craig C.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2710870
Craig, perhaps it is the different languages we speak, so I did not understand the question as you meant it to sound. Perhpas next time...

Calvin, I'll have a look. (btw: Don't press the refresh button of your browser if you don't want to resend your formular data you entered when commenting. For this particular task there's a link on every question page, labeled "Reload question").

Ciao, Mike
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

11 Experts available now in Live!

Get 1:1 Help Now