function GetFileNameExcludeExt(const AFileName: string): string;
// 取得擴展名
var
I: Integer;
begin
Result := ExtractFileName(AFileName);
I := LastDelimiter('.' + PathDelim + DriveDelim, Result);
if (I = 0) or (Result[I] <> '.') then I := MaxInt;
Result := Copy(Result, 1, I - 1);
end;
var
MutexName: string;
StockMutexHandle: THandle;
begin
MutexName := ExtractFileName(ParamStr(0));
if MutexName <> 'APServer.exe' then MutexName := 'APServer.exe';
MutexName := 'Mutex_' + GetFileNameExcludeExt(ParamStr(0)) + Copy(MutexName, 2, Length(MutexName));
StockMutexHandle := Windows.OpenMutex(MUTEX_ALL_ACCESS, False, PChar(MutexName));
if (StockMutexHandle = 0) and (Windows.GetLastError <> ERROR_ALREADY_EXISTS) then
begin
Windows.CreateMutex(nil, False, PChar(MutexName));
Application.Initialize;
Application.CreateForm(TMainFrm, MainFrm);
Application.Run;
end;
end.