I was struggling with a scenario where I had one process running as admin and another process running as non-admin user. The first admin-process should open a pipeStream to allow the other process sending some message information.
Here I had multiple problems:
- I had to set the permission for the pipeStream allowing the client to write some data into this pipe even if the user is not the same and even no admin
- The admin process should wait for the connection via 'WaitForConnectionAsync'
- The pipeStream should be properly closed to allow running the same code again.
See below my solution.
Here is my server-side code that creates the pipeStream:
and here the client-side code to send a message to the other process:
I hope this code-snippets will help others with a similar use case and also explains a little bit some details working with a NamedPipeServerStream.