[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

How can I prevent the second instance of my application to to be run using delphi

Hello . I'm going to prevent the other instanses of my application to be run , while the first instanse is still running , Please offer me a sample code .
0
Iman_Davoodian
Asked:
Iman_Davoodian
1 Solution
 
Pierre CorneliusCommented:
0
 
Steven-FernandezCommented:
Try this:

Here is an example:

Uses: Windows, Dialogs

Insert code in the projects source (.dpr file)

var
  MutexHandle : THandle;
begin
  MutexHandle := CreateMutex(nil, True, 'AppMutex');
  if MutexHandle <> 0 then
  begin
    if GetLastError = ERROR_ALREADY_EXISTS then
    begin
      Showmessage('An Instance of this application is already running.');
      CloseHandle(MutexHandle);
      Halt;
    end;
  end;

{Application.Initialise, run etc... follows from here}

end.




0

Featured Post

Technology Partners: 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!

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