Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Apr : Singelton application for different TS-sessions

www.cryer.info
Managed Newsgroup Archive

Singelton application for different TS-sessions

Subject:Singelton application for different TS-sessions
Posted by:"Jonas Gunnarsson" (gus..@spray.se)
Date:Thu, 28 Apr 2005 17:41:33

Hi!

I have encountered some problem using the GlobalMutex.
When using TerminalService(TS) and several logons the GlobalMutex don't
seems to work. Any tip?

<code id=ServerManager.dpr>
..
const
   GLOBAL_MUTEX_NAME = 'MY_GLOBAL_SERVER_MANAGER_MUTEX';
var
   GlobalMutex: THandle;
begin
   SetLastError(NO_ERROR);
   GlobalMutex := CreateMutex(nil, False, GLOBAL_MUTEX_NAME);
   if GetLastError = ERROR_ALREADY_EXISTS then
   begin
     MessageBox(0, 'Another instance is already running', 'Information',
MB_OK);
   end else
   begin
     Application.Initialize;
     Application.CreateForm(TfrmServerManager, frmServerManager);
   Application.Run;
   end;
   CloseHandle(GlobalMutex);
end.
</code>

Best regards
/Jonas

Replies:

www.cryer.info
Managed Newsgroup Archive