Solved

Don't let twice running

Posted on 2006-07-17
5
260 Views
Last Modified: 2010-04-16
Dear Experts

I wanna write an application if it runs, and user run it again (click on it icon), it doesn't create again and just show previous application as some programs, for example winamp, word and .... u cann't run winamp twice.it should check if it has runned previousely, don't run again
PLZ help me.

Regards
0
Comment
Question by:shaasousaa
5 Comments
 
LVL 9

Accepted Solution

by:
sun4sunday earned 50 total points
ID: 17120094
check this
http://delphi.about.com/library/code/ncaa100703a.htm    //source code
http://delphi.about.com/od/windowsshellapi/l/aa100703b.htm // a neat explantion start here


In this article(with soure code) you'll learn how to "run-once enable"
a Delphi application that can check for its previous
(running) instance. Along the process, several techniques
of implementing such a check will be discussed; as well
as how to bring your already running application to the
foreground, if a user tries to run it "one more time". By
the end of the article you'll have a copy-to-go code to
control the behavior of your application's multiple instances:
with the option to limit the number of running instances.

sun4sunday
0
 
LVL 9

Expert Comment

by:sun4sunday
ID: 17120099
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 17120264
TJvAppInstances from the Jedo components (http://homepages.borland.com/jedi/jvcl/) will allow you to limit your application to a specific number of instances. It will also activate the running process if required and is just the simplest way. It also provides you some additional functionality that you might like to use. For example, it can transfer the commandline parameters from the second process to the first one.
0
 
LVL 7

Expert Comment

by:kfoster11
ID: 17123021
Not sure where I downloaded this freeware control.

ADP Instance control.  Just drop it on the main form and tell it how many instances are allowed.

www.certss.com\downloads\expertexchange\adp.zip
0
 
LVL 6

Expert Comment

by:saravananvg
ID: 17127986
Hello Sir,

  You could do as follows.


program Project1;

uses
  Windows, Messages, Forms,
  Unit1 in 'Unit1.pas' {MainWindow};

{$R *.res}

begin
if CreateMutex(nil, true, 'MyAppIsAlreadyOpened') <> 0 then
if GetLastError = ERROR_ALREADY_EXISTS then begin
  // app is already opened
  SetForegroundWindow(FindWindow('TMainWindow', 'MainWindow'));
end else begin
  // app is not opened
  Application.Initialize;
  Application.CreateForm(TMainWindow, MainWindow);
  Application.Run;
end;
end.

with regards,
padmaja.
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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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 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…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

16 Experts available now in Live!

Get 1:1 Help Now