EventWaitHandle access denied .NET Standard 2.0

172 views Asked by At

I am using a global EventWaitHandle to implement an inter-process handshake for a named pipe. The server (running as service with admin priviliges) opens the EventWaitHandle while the client checks for the open handle before connecting to the named pipe.

Using both with the same priviliges, its fine. Running the server as admin and client normal results in: System.UnauthorizedAccessException: Access to the path 'Global\DEMO_CONNECTION_OPEN_HANDLE' is denied.

I am using .NET Standard 2.0. Hence, simple solutions such as EventHandleRights are not available. Is there any way to set access rights (e.g. while creating the handle) or elevate the client code for the EventWaitHandle only?

Example code server:

var handshakeHandle = new EventWaitHandle(false, EventResetMode.ManualReset,
    String.Format(@"Global\{0}", $"{ConnectionName.ToUpper()}_CONNECTION_OPEN_HANDLE"));

CreateServerPipe(ConnectionName);

handshakeHandle.Set();
await serverStream.WaitForConnectionAsync();
handshakeHandle.Reset();

Example code client:

// Results in Exception:
var handshakeHandle = EventWaitHandle.OpenExisting(
    String.Format(@"Global\{0}", $"{ConnectionName.ToUpper()}_CONNECTION_OPEN_HANDLE"));

CreateClientPipe(ConnectionName);

if (!handshakeHandle.WaitOne(millisecondsTimeout))
    throw new TimeoutException($"Cannot access within timeout.");

clientStream.Connect(millisecondsTimeout);

Any hint is much appreciated!

Edit: Any recommendation for a different approach than EventWaitHandle to implement an inter-process handshake is welcome.

0

There are 0 answers