NamedPipeClientStream无法访问会话0下的NamedPipeServerStream

Ksi*_*ice 16 c# named-pipes windows-7

我有NamedPipeClientStream连接到NamedPipeServerStream.他们交换了几条消息,然后关闭NamedPipeClientStream,同时重新创建NamedPipeServerStream并继续侦听客户端管道.(我无法使用异步服务器管道,所以这是一种狗钉子)

在从普通用户会话启动的客户端流中,客户端 - 服务器交互正常.

但是有一种情况是在Win7和win2008服务器上从会话0启动客户端管道.发生这种情况时,我在客户端流中出错:

"拒绝访问该路径"

问题是什么?怎么避免呢?

对不起,我无法告诉你有关异常的更多信息.只有我在日志中有此消息.我无法从零会话调试我的程序,可以吗?

服务器流代码:

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);
Run Code Online (Sandbox Code Playgroud)

安全设置可能有问题吗?

和客户端代码:

using (NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", General.PIPENAME, PipeDirection.InOut))
{
    try
    {
        Console.WriteLine("Connecting with pipe...");
        pipeStream.Connect(General.CONNECTIONTIMEOUT);
        Console.WriteLine("Pipe connection established");
        //..do something..
    }
    //...
}
Run Code Online (Sandbox Code Playgroud)

服务器在LocalSystem下作为Windows服务启动.客户端 - 是一个简单的控制台应用程序.它是由LocalSystem服务启动的另一个应用程序启动的.

Ksi*_*ice 16

看起来,问题是你的安全设置:

System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null);
Run Code Online (Sandbox Code Playgroud)

应该 :

System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);
Run Code Online (Sandbox Code Playgroud)

谢谢微软的社区

  • 链接坏了.我讨厌微软不断重组他们的网站,并在互联网上留下数百万条破损的链接. (13认同)