EventWaitHandle - UnauthorizedAccessException

G

Guest

Hi all!

I'm trying to use a named EventWaitHandle to signal events between processes
that run on the same computer. One of them is a service running as SYSTEM and
the other one is a normal user. Creating the handle seems to be no problem,
but when the other process is calling EventWaitHandle.OpenExisting with the
same name, an UnauthorizedAccessException is thrown with the message "Access
to the path is denied.".

Any idea on how to make it work? I'm completely clueless on this one...

- Kristoffer -
 
V

Vadym Stetsyak

Hello, Kristoffer!

KP> I'm trying to use a named EventWaitHandle to signal events between
KP> processes that run on the same computer. One of them is a service
KP> running as SYSTEM and the other one is a normal user. Creating the
KP> handle seems to be no problem, but when the other process is calling
KP> EventWaitHandle.OpenExisting with the same name, an
KP> UnauthorizedAccessException is thrown with the message "Access to the
KP> path is denied.".

What process is calling EventWaitHandle.OpenExisting? Service or application under common user?

Can you post code, where you create and initialize EventWaitHandle object?

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
G

Guest

When I test it, I start the executable first and then the service. If the
executable is running as an administrator, there is no problem. If it is a
normal user, the service will fail to open the existing event.

( If I start the service first, then the program as a normal user, then the
program will fail at an earlier stage, when a mutex is created with mutex =
new System.Threading.Mutex(false, "MyMutexName"); )

The code I use is taken from the help on the
EventWaitHandle.SetAccessControl method. I took Main, made it a public static
method with the name as an inparam and removed the deny rule on Synchronize
and Modify when the named event is created.

So, I guess the problem is to figure out how to give the normal user access
to work with a named Mutex/EventWaitHandle...

- Kristoffer -
 
G

Guest

Ahh... simple when you know the answer...

To create a named Mutex or EventWaitHandle that can be shared between users,
you should create Allow access rules for the identity "Everyone".

EventWaitHandleSecurity ewhSec =
new EventWaitHandleSecurity();

EventWaitHandleAccessRule rule =
new EventWaitHandleAccessRule("Everyone",
EventWaitHandleRights.Synchronize |
EventWaitHandleRights.Modify,
AccessControlType.Allow);
ewhSec.AddAccessRule(rule);

ewh = new EventWaitHandle(false,
EventResetMode.AutoReset,
ewhName,
out wasCreated,
ewhSec);

- Kristoffer -
 
V

Vadym Stetsyak

Hello, Kristoffer!

KP> ( If I start the service first, then the program as a normal user, then
KP> the program will fail at an earlier stage, when a mutex is created with
KP> mutex = new System.Threading.Mutex(false, "MyMutexName"); )

What is the problem here? What exception is being thrown?
I suppose that mutex object is already created by the service without ( default ) mutex security.

To open mutex you can use same approach as for EventWaitHandle. That is Mutex.OpenExisting(...)
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
V

Vadym Stetsyak

Hello, Kristoffer!

KP> To create a named Mutex or EventWaitHandle that can be shared between
KP> users, you should create Allow access rules for the identity
KP> "Everyone".

I think using "Everyone" is not secure, it will be better to limit it to particular user.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 

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