How to Prevent Running an Application more than once - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to Prevent Running an Application more than once

dubidubi Posts: 121Member
Hai friends,
I like to stop running an application which is
already opened,i.e when the .Exe of the application is clicked
second time,it should not run indicating a Message as
"The Application is Already Running".
For example we cannot open more than one Yahoo Messenger at the
same time.

Thanks for your suggestions.

Comments

  • zibadianzibadian Posts: 6,349Member
    : Hai friends,
    : I like to stop running an application which is
    : already opened,i.e when the .Exe of the application is clicked
    : second time,it should not run indicating a Message as
    : "The Application is Already Running".
    : For example we cannot open more than one Yahoo Messenger at the
    : same time.
    :
    : Thanks for your suggestions.
    :
    This message contains a code to check if the same application is already running: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=4&MsgID=91067
  • GaashiusGaashius Posts: 349Member
    : : Hai friends,
    : : I like to stop running an application which is
    : : already opened,i.e when the .Exe of the application is clicked
    : : second time,it should not run indicating a Message as
    : : "The Application is Already Running".
    : : For example we cannot open more than one Yahoo Messenger at the
    : : same time.
    : :
    : : Thanks for your suggestions.
    : :
    : This message contains a code to check if the same application is already running: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=4&MsgID=91067
    :
    I copied the msg before it will be deleted :

    The following is an alternative solution to using atoms to prevent multiple instances of an application (see Pam Mundy's article on Atoms). It is a modified version of the technique presented in Teixeira and Pacheco's "Delphi 4 Developer's Guide".

    Example of use:

    if not AppIsAlreadyRunning('MyAppName') then
    begin
    Application.Initialize;
    { ... }
    Application.Run;
    end; { if }
    (*
    Module Name : Just1Fix.pas
    Description : Module to insure that just one copy of an application
    is running at any given time.
    Call AppIsAlreadyRunning in Project file, and
    bypass everything if the function returns True.
    Note that AppIsAlreadyRunning should only be called once.
    Designed for Delphi 3 or higher, with long strings
    enabled as default in compiler options.

    Copyright (c) 1999 ASI/EDI, Inc. All rights reserved.
    Written by Bill Sorensen (tzimisce@mwaccess.net, http://www.Will.brinet.net).
    Source code published by permission of ASI/EDI, Inc. (http://www.asiedi.com).

    ASI/EDI Inc. and the author expressly disclaim any warranty,
    express or implied, for this code and documentation.
    Use it at your own risk.
    *)

    unit Just1Fix;

    interface

    function AppIsAlreadyRunning(const sUniqueText: String): Boolean;

    implementation

    uses
    Windows;

    function AppIsAlreadyRunning(const sUniqueText: String): Boolean;
    begin
    // If the named Mutex already exists, there's another copy running.

    if OpenMutex(MUTEX_ALL_ACCESS,False,PChar(sUniqueText)) <> 0 then
    Result := True
    else
    Result := (CreateMutex(nil,False,PChar(sUniqueText)) = 0);
    // Otherwise, create a Mutex with a unique name.
    // This should succeed, unless we're out of resources.

    // Mutex handle is closed automatically when the process terminates.
    // Mutex is destroyed when the last handle to it is closed.
    end;

    end.

    ---

    Regards

    /Filip

    ****************
    Any questions? Just ask!

    :-) [b][blue]GAASHIUS[/blue][/b] :-)


Sign In or Register to comment.