Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 命名管道客户端无法连接到作为网络服务运行的服务器_C#_Windows_Permissions_Windows Services_Named Pipes - Fatal编程技术网

C# 命名管道客户端无法连接到作为网络服务运行的服务器

C# 命名管道客户端无法连接到作为网络服务运行的服务器,c#,windows,permissions,windows-services,named-pipes,C#,Windows,Permissions,Windows Services,Named Pipes,我有一个在网络服务帐户下运行的服务。该服务仅设置命名管道并侦听连接: NamedPipeServerStream listeningPipe = new NamedPipeServerStream("ourservicepipe", PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.Asynchronous

我有一个在网络服务帐户下运行的服务。该服务仅设置命名管道并侦听连接:

NamedPipeServerStream listeningPipe = new NamedPipeServerStream("ourservicepipe",
    PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, 
    PipeTransmissionMode.Message, PipeOptions.Asynchronous);
listeningPipe.BeginWaitForConnection(OnPipeConnected, listeningPipe);
我有一个应用程序在同一台机器上的标准用户帐户上运行。它尝试连接到由服务创建的命名管道:

NamedPipeClientStream pipe = new NamedPipeClientStream(".", "ourservicepipe", 
    PipeDirection.InOut, PipeOptions.Asynchronous);
pipe.Connect(2000);
pipe.ReadMode = PipeTransmissionMode.Message;
当我调用
Connect
时,它最终抛出一个
invalidoOperationException
。如果我在同一个用户上运行该服务,它连接良好。如果我以管理员的身份运行客户端,它连接良好。这使我相信问题在于权限,但我不知道在安装过程中需要设置哪些权限


如何允许客户端连接到服务器,而不要求客户端以管理员身份运行?

管道服务器是使用默认服务DACL创建的,因此只有管理员或系统用户可以连接到管道。您需要使用适当的访问规则设置管道服务器,以使所有客户端连接成功。下面是设置访问规则以访问所有人以访问管道的代码:

    PipeSecurity pipeSa = new PipeSecurity(); 
    pipeSa.SetAccessRule(new PipeAccessRule("Everyone", 
                    PipeAccessRights.ReadWrite, AccessControlType.Allow)); 
    listeningPipe.SetAccessControl(pipeSa);

最好只定义一组最小的用户来访问管道服务器,以确保其安全。

我不允许发表评论,但我想指出,根据操作系统语言的不同,dvansanth的回答是正确的。 如果操作系统语言不是英语,“Everyone”组可能不存在

我是这样解决的:


注意:这是为“已验证用户”而不是“所有人”尝试执行未经授权的操作-pipe.SetAccessControl(pipeSa);是否需要创建SecurityIdentifier.ToString()?
PipeSecurity pipeSa = new PipeSecurity();
pipeSa.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null), 
                PipeAccessRights.ReadWrite, AccessControlType.Allow)); 
listeningPipe.SetAccessControl(pipeSa);