Mega Code Archive

 
Categories / Delphi / Examples
 

Start an application exclusive

Title: Start an application exclusive Question: Prevent duplicate start of an application Answer: Start an application exclusive implementation var mHandle: THandle; // Mutexhandle Projekt: string; initialization Project := ''; // define your project-name here mHandle := CreateMutex(nil, True, PChar(Projekt)); if GetLastError = ERROR_ALREADY_EXISTS then begin showMessage('Project ' + Project + ' is still running'); halt; // kill the second instance end; finalization // alt end free the mHandle if mHandle 0 then CloseHandle(mHandle) end. Tested under Win9x and Win2K