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

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

本文介绍了命名管道客户端无法连接到作为网络服务运行的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a service running under the Network Service account. The service just sets up a named pipe and listens for connections:

NamedPipeServerStream listeningPipe = new NamedPipeServerStream("ourservicepipe",
    PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances,
    PipeTransmissionMode.Message, PipeOptions.Asynchronous);
listeningPipe.BeginWaitForConnection(OnPipeConnected, listeningPipe);

我有一个应用程序在同一台计算机上的标准用户帐户上运行.它尝试连接到服务创建的命名管道:

I have an application running on a standard user account on the same machine. It tries to connect to the named pipe created by the service:

NamedPipeClientStream pipe = new NamedPipeClientStream(".", "ourservicepipe",
    PipeDirection.InOut, PipeOptions.Asynchronous);
pipe.Connect(2000);
pipe.ReadMode = PipeTransmissionMode.Message;

当我呼叫Connect时,它最终抛出了InvalidOperationException.如果我在同一用户上运行该服务,则连接正常.如果我以管理员身份运行客户端,则连接正常.这使我相信问题出在权限上,但是我不知道在安装过程中需要设置哪些权限.

When I call Connect, it ends up throwing an InvalidOperationException. If I run the service on the same user, it connects fine. If I run the client as an administrator, it connects fine. This leads me to believe the problem is with permissions, but I have no idea which permissions I need to set during installation.

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

How can I allow the client to connect to the server, without requiring that the client run as an administrator?

推荐答案

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

Pipe server is created with the default service DACL so that only the administrator or system user can connect to the pipe. You need to set the pipe server with proper access rules to make all client connection to succeed. Below is the code to set the access rule to access everyone to access the pipe:

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

总是最好只定义一组最少的用户来访问管道服务器以使其安全.

It always better to define only a minimal set of users to access the pipe server to make it secure.

这篇关于命名管道客户端无法连接到作为网络服务运行的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:03