Mega Code Archive

 
Categories / Delphi / System
 

Allow only one instance of a program [works also under nt]

Just add this unit to your uses clause uses Single; and your program will not be started twice: unit Single; interface implementation uses Windows, SysUtils; var hnd: THandle; initialization hnd := CreateMutex(nil, True, 'irgendwaseinmaliges'); if GetLastError = ERROR_ALREADY_EXISTS then Halt; finalization if hnd <> 0 then CloseHandle(hnd); end.