Tag: 命名管道

为只读命名管道启用MessageMode时的C#UnauthorizedAccessException(NamedPipeClientStream类)

.NET中的NamedPipeClientStream类存在问题,因为您无法使用PipeDirection.In创建此类的实例,然后成功将ReadMode更改为PipeTransmissionMode.Message 。 尝试这样做会引发UnauthorizedAccessException 。 虽然管道通常用于在进程之间进行通信,但是在单个进程中的这个简单示例显示了问题: var pipeOut = new NamedPipeServerStream(“SomeNamedPipe”, PipeDirection.Out, 1, PipeTransmissionMode.Message); var pipeIn = new NamedPipeClientStream(“.”, “SomeNamedPipe”, PipeDirection.In); pipeIn.Connect(); pipeIn.ReadMode = PipeTransmissionMode.Message; 尝试设置ReadMode属性时,此代码将抛出UnauthorizedAccessException 。 在搜索有关此问题的信息时,我在其他地方找到了对它的引用,例如: 命名管道问题:System.UnauthorizedAccessException:拒绝访问路径。 WPF – 使用Windows管道协议的消息传递 PipeTransmissionMode.Message:.NET命名管道如何区分消息? 所有这些post都提到这是“奇怪的”,“奇怪的”等,但不解释“为什么”它不起作用,并且都给出相同的解决方法,“出于一些奇怪的原因”设置管道方向到InOut使它工作。 确实,这确实使它工作,但它需要从根本上改变管道的两端定义到全双工,而不是单向,我认为这是一个非常糟糕的方法,除非你是能够更改客户端和服务器,这甚至可能是不可能的。 我的问题是,为什么在入站管道上启用消息模式会导致exception,是否有更好的方法来解决此问题,而不是将管道更改为双向模式?

NamedPipeClientStream无法访问会话0下的NamedPipeServerStream

我有NamedPipeClientStream连接到NamedPipeServerStream。 他们交换了几条消息,然后关闭了NamedPipeClientStream,同时重新创建NamedPipeServerStream并继续侦听客户端管道。 (我无法使用异步服务器管道,所以这是一种狗钉子) 在从普通用户会话启动的客户端流中,客户端 – 服务器交互正常。 但是有一种情况是从Win7和win2008服务器上的会话0启动客户端管道。 发生这种情况时,我在客户端流中出错: “拒绝访问该路径” 问题是什么? 怎么避免呢? 对不起,我无法告诉你有关exception的更多信息。 只有我在日志中有此消息。 我无法从零会话调试我的程序,可以吗? 服务器流代码: PipeSecurity ps = new PipeSecurity(); System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null); PipeAccessRule par = new PipeAccessRule(sid, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow); ps.AddAccessRule(par); pipeClientConnection = new NamedPipeServerStream(General.PIPENAME, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, General.BUFFERSIZE, General.BUFFERSIZE, ps); Console.Write(“Waiting for client connection…”); IAsyncResult result = pipeClientConnection.BeginWaitForConnection(OnPipeConnected, pipeClientConnection); 安全设置可能有问题吗? […]

C#3.5 – 通过网络连接命名管道

在网络中通过C#设置命名管道的正确方法是什么? 目前我有两台机器,’客户’和’服务器’。 服务器以下列方式设置其管道: NamedPipeServerStream pipeServer = new NamedPipeServerStream( “pipe”, PipeDirection.InOut, 10, PipeTransmissionMode.Byte, PipeOptions.None) pipeServer.WaitForConnection(); //… Read some data from the pipe 客户端以下列方式设置其连接: NamedPipeClientStream pipeClient = new NamedPipeClientStream( “server”, “pipe”, PipeDirection.InOut); pipeClient.Connect(); //This line throws an exception //… Write some data to the pipe 可以通过转到“\\ server”在网络上访问“服务器”计算机。 每当我运行程序时,我都会收到一个System.UnauthorizedAccessException,其中显示“拒绝访问路径”。 当我在本地计算机上运行服务器和客户端并尝试连接到“。”时,代码工作正常。 与客户。

如果设置了PipeSecurity,则在创建第二个实例时,命名管道服务器会抛出UnauthorizedAccessException

我正在尝试编写一个(提升权限)服务,该服务将与非特权winforms应用程序进行通信。 我能够有两个控制台应用程序(一个没有升级)应答来回没问题,但我在服务和winforms应用程序时遇到问题。 管道的第一个实例完美无缺。 然而,在我的客户端连接之后,我尝试创建一个新实例,以便在第二个客户端连接时准备就绪,但NamedPipeServerStream的构造函数会引发exception System.UnauthorizedAccessException was unhandled Message=Access to the path is denied. Source=System.Core StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.Pipes.NamedPipeServerStream.Create(String fullPipeName, PipeDirection direction, Int32 maxNumberOfServerInstances, PipeTransmissionMode transmissionMode, PipeOptions options, Int32 inBufferSize, Int32 outBufferSize, PipeAccessRights rights, SECURITY_ATTRIBUTES secAttrs) at System.IO.Pipes.NamedPipeServerStream..ctor(String pipeName, PipeDirection direction, Int32 maxNumberOfServerInstances, PipeTransmissionMode transmissionMode, PipeOptions options, Int32 inBufferSize, Int32 outBufferSize, PipeSecurity […]

C#中的multithreadingNamePipeServer

你好 我想使用NamedPipeServerStream ,这是.NET 3.5中用于namedpipe通信的新function。 我想写multithreading管道服务器。 它是默认处理还是我应该为此编写代码。 我的管道服务器应该一次处理多个请求 任何解决方案或代码?