Answer the question
In order to leave comments, you need to log in
How to connect to a named pipe without admin rights?
Hello. There are two C# applications - a service (windows service) and a client application that exchange information via named pipes (Named Pipes). The problem is that the client application can only connect to the named pipe service with administrative privileges. I found a solution on the net, which suggests assigning a PipeSecurity to a server named pipe containing one or more PipeAccessRule. After applying this approach, the server application crashes with a System.UnauthorizedAccessException. Tell me how to connect to the service of a client application that is running without admin rights via a named pipe? I do this:
Windows Service
protected override void OnStart(string[] args)
{
new Thread(() =>
{
while (true)
{
using (var pipe = new NamedPipeServerStream("test", PipeDirection.InOut, 1, PipeTransmissionMode.Byte))
{
var ps = new PipeSecurity();
ps.AddAccessRule(new PipeAccessRule(WindowsIdentity.GetCurrent().Name, PipeAccessRights.FullControl, AccessControlType.Allow));
pipe.SetAccessControl(ps);
pipe.WaitForConnection();
int x = pipe.ReadByte();
pipe.WriteByte((byte)(x + 1));
}
}
})
{ IsBackground = true }.Start();
}
using (var pipe = new NamedPipeClientStream(".", "test", PipeDirection.InOut))
{
pipe.Connect();
pipe.WriteByte(100);
int x = pipe.ReadByte();
Console.WriteLine(x);
}
Answer the question
In order to leave comments, you need to log in
The server needs these settings
var pipeSecurity = new PipeSecurity();
pipeSecurity.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question