Groups | Blog | Home
all groups > dotnet security > january 2007 >

dotnet security : EventWaitHandle between a service and an application.



Jon Curry
1/29/2007 10:36:01 AM
I have a service that starts a thread which waits for a global
EventWaitHandle to be set, writes to the application event log, and waits
for the next set.

I have a simple windows forms application with a button that sets the event
on button click.

My service never receives the event on Windows 2003 server, but it works
fine on XP. The service is running as Network Service. I tried changing the
service to run as my domain user (which is an admin on that box) but still
nothing.

Using: .Net 2.0

The EventWaitHandle is created the same way in both the service and
application:
------------
EventWaitHandleSecurity security = new EventWaitHandleSecurity();
bool created;

security.AddAccessRule( new EventWaitHandleAccessRule(
"Everyone",
EventWaitHandleRights.FullControl,
AccessControlType.Allow ) );

globalEvent = new EventWaitHandle(
false,
EventResetMode.AutoReset,
"My.Test.Service",
out created,
security );
------------

I've search and searched and experimented with different things, but have
hit nothing but brick walls. Any help would be greatly appreciated.

Jon
Morgan Skinner
2/15/2007 9:09:19 AM
Jon,

You're not actually creating a global wait handle with the code you have here - there is a specific syntax for constructing a truly global handle.

You need to prefix the event name with "Global\" - then you really will have just one system wide handle.

The reason for this is that, without the Global\ prefix, the actual name of the event handle is based on your windows session. Your service is typically in session 0, and your application typically in session 1. So, you have a session global handle, but not a system global handle.

You can view the list of objects that a given .exe has opened using process explorer (see www.sysinternals.com for details). From this you would see that the actual name of the wait handle is currently prefixed with something like...

\Sessions\1\BaseNamedObjects\{your event name}

With Global\ on the front it will then be...

\BaseNamedObjects\{your event name}

Hope this helps,

AddThis Social Bookmark Button