Click to See Complete Forum and Search --> : Single instance app and multi logons


aneesh.joy
May 26th, 2006, 06:29 AM
Hi all,

I have a single instance application which is started automatically
on user logons.

Single instance is maintained using a global mutex lock.

Now the problem i m facing when running on multi logon machines is as follows.


UserA logs in --> single.exe is started

UserB logs in --> single.exe detects another instance and exits.

UserA logs out --> running single.exe exits.

Now there is no instance of single.exe is running on that computer.

I can not make this program a windows service since it should be
running as any logged on user as owner.

Do you have any ideas to solve this problem ?

Cheers

Andreas Masur
May 26th, 2006, 05:38 PM
Simple solution...incorporate the user name into the mutex unique name... ;)

JamesSchumacher
May 26th, 2006, 07:41 PM
(Since you mentioned multi logon, this should work for you - Local\ prefix on mutex name) But...

What OS targets are you targeting?

Is it XP and newer only?

Because I believe XP uses terminal services to implement fast user switching.

If that is the case:


The name can have a "Global\" or "Local\" prefix to explicitly create the object in the global or session name space


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createmutex.asp

However...


Windows 2000: If Terminal Services is not running, the "Global\" and "Local\" prefixes are ignored. The remainder of the name can contain any character except the backslash character.

aneesh.joy
May 27th, 2006, 07:27 AM
Thanks for the suggestions.

But that does not completely solve my problem. I can not run multiple instances in any case.

In the suggested method each user will have one instance of the app running right ?

Or may be I did not understand.


Cheers

Andreas Masur
May 27th, 2006, 08:57 AM
What OS targets are you targeting?

Well...if he is running Windows 2000, he wouldn't have any problems since Windows 2000 didn't implement fast user switching... ;)

Andreas Masur
May 27th, 2006, 08:58 AM
But that does not completely solve my problem. I can not run multiple instances in any case.
Well...then I don't understand the problem in the first place. If you always run only one instance the method you are using (creating a unique mutex) is fine. :confused: