Link to home
Start Free TrialLog in
Avatar of shaasousaa
shaasousaa

asked on

Don't let twice running

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
ASKER CERTIFIED SOLUTION
Avatar of sun4sunday
sun4sunday
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Wim ten Brink
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.
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
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.