C# Change Named Pipe Access Permissions

39 Views Asked by At

I am getting an Unauthorized Access exception when I try to add security to my pipe. I gather that this needs to be defined when I create the pipe, or at least add a permission to change the pipe, but I don't see how to do that either. All examples online have too many arguments. My compiler says that NamedPipeServerStream maxes out at 7 and does not have any security options. Microsoft agrees with me.

using System.IO.Pipes;
NamedPipeServerStream pipeServer;
pipeServer = new NamedPipeServerStream("PipeName", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
PipeSecurity clientPipeSecurity = new PipeSecurity();                    
//PipeAccessRule clientAccessRule = new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow);
//clientPipeSecurity.AddAccessRule(clientAccessRule);     
PipeAccessRule clientAccessRule = new PipeAccessRule("Domain Users", PipeAccessRights.ReadWrite, AccessControlType.Allow);
clientPipeSecurity.AddAccessRule(clientAccessRule);            
                
pipeServer.SetAccessControl(clientPipeSecurity);

Did include the wrong library? Why won't this compile like other posts say it should? All I can think is that those examples are too old .NET has dropped that option for some reason.

pipeServer = new NamedPipeServerStream("DAQUpdater",
      PipeDirection.InOut,
      1,
      PipeTransmissionMode.Message,
      PipeOptions.Asynchronous,
      0x4000,
      0x400,
      pipeSecurity);

'NamedPipeServerStream' does not contain a constructor that takes 8 arguments

0

There are 0 best solutions below