Using a Global Mutex

V

Viviana Vc

Hi all,

I have an application App1, that after doing some stuff starts App2.
Both are per user applications.
Now, on an XP with FUS enabled or an Win2k with Terminal Services, there
can be at the same time more than one user logged in, and for these
situations I would like to do the following:
a)- for user1, App1 starts and then it starts App2 (normal situation)
b)- for user2, I have to find out in App1 if the App2 is already running
for another user, because in that case I have to do some stuff

For doing the step b) I was thinking to do:
- App2 when starts creates a mutex with "Global\\..." (to be in the
global namespace)
- App1 when starts checks if that mutex already exists (i.e:
if(CreateMutex(NULL, TRUE, MyAppOneInstanceMutex))
{if(ERROR_ALREADY_EXISTS == GetLastError()) // the mutex was already
created...}) and in this way App1 can be sure that on that machine there
is already a running App2 (for that user or another one).

Questions:
1) Would this be a nice solution to detect from App1 that App2 is
already running?
2) In MSDNL is written: "Starting with Windows Server 2003, the creation
of a global section from a session other than the initial system session
(where clients run) is a privileged operation. Because of this, an
application running in an arbitrary Terminal Server session must have
SeCreateGlobalPrivilege enabled in order to create a global section
successfully. Note that the privilege check is limited to the creation
of section objects, and does not apply to opening existing ones. For
example, if a service or the system creates a global section, any
process running in any session can access that section provided that the
user has the necessary access."

Can somebody explain what that means? What does "from a session other
than the initial system session (where clients run)" mean? Which is
initial system session? The first logged in user?
In my case this issue can affect my App2 which will try to create a
global mutex (and it might be that user1 doesn't have my app installed,
so the first time when my app will be run can be when user2 logs in, so
the global mutex will be just then created)? If yes, how could I set the
SeCreateGlobalPrivilege privilege?

Thanks in advance,
Viv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top