I recieved an Event Viever entry from one of my users saying that Unauthorized Access Exception happened. The process is started from a service as a SYSTEM. I was able to narrow down the error to the part where NamedPipeServerStream is created:
  // <error in this block>
  PipeSecurity pipeSa = new PipeSecurity(); 
  pipeSa.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow));
  NamedPipeServerStream np = new NamedPipeServerStream("streamname", PipeDirection.InOut,1,PipeTransmissionMode.Message,PipeOptions.None,16383,1, pipeSa);
  // </error in this block>
  while (true){
     try{
        if (!np.IsConnected)
           np.WaitForConnection();
     }catch(Exception e){
     }
  }
I am pretty sure that the error is in the 3 line block above. It doesn't happen on any of my computers so I can't repeat the error. What in the above code is not considered best practice and can cause errors?
error message image:
