Prevent multiple instances of an application

Please discuss general Delphi programming topics here.

Prevent multiple instances of an application

Postby mathgod » January 17th, 2010, 8:04 am

I already know how to prevent multiple instance of my own application. However, I am drawing a blank on how to prevent the spawning of a second instance of another application. I know about the taskkill command and scheduling the batch file to run.

I want to detect when "parser.exe" spawns a second instance and kill off that second process.
User avatar
mathgod
Junior Member
Junior Member
 
Posts: 35
Joined: December 15th, 2007, 4:36 pm
Location: Middle of New Mexico, USA

Re: Prevent multiple instances of an application

Postby SaeedShekari » January 18th, 2010, 7:46 am

I do the following for the same purpose, Hope this will help you...

Code: Select all
Procedure DoLunch;
Var
  hw: Hwnd;
Begin
  Hw:= FindWindow('YourWindowNameInHere', Nil);
  //Check FindWindow Win API Function for 'YourWindowNameInHere'
  If (HW = 0) Then
  Begin
    //Your application is not running
  End;
End;
Saeed Shekari
User avatar
SaeedShekari
Active Member
Active Member
 
Posts: 20
Joined: March 8th, 2008, 2:01 pm
Location: UAE

Re: Prevent multiple instances of an application

Postby mathgod » January 19th, 2010, 2:32 am

Thank you. Your solution works well.
User avatar
mathgod
Junior Member
Junior Member
 
Posts: 35
Joined: December 15th, 2007, 4:36 pm
Location: Middle of New Mexico, USA


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron