Title: Not Allow That Your EXE File Twice Running.
Question: How To Protect My EXE File That only one instance run.
/By OneInstanceUint
Answer:
unit OneInstanceUnit;
interface
uses
Windows;
const
MutexName = 'Mymutex.';
function IsUniqueInstance: Boolean;
procedure ShowErrorMessage;
implementation
uses StringsUnit;
function IsUniqueInstance: Boolean;
var
Mutex: THandle;
begin
Result := False;
Mutex := CreateMutex(nil, FALSE, MutexName);
if Mutex = 0 then
Exit;
if WaitForSingleObject(Mutex, 0) = WAIT_OBJECT_0 then
Result := True
else
CloseHandle(Mutex);
end;
procedure ShowErrorMessage;
begin
MessageBox(GetDesktopWindow,
PChar('Only One Instance Must Be Run'),
PChar('Error'), MB_OK or MB_ICONERROR);
end;
end.