Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
649 views
in Technique[技术] by (71.8m points)

c# - NamedPipeClientStream can not access to NamedPipeServerStream under session 0

I have NamedPipeClientStream which connects to NamedPipeServerStream. They exchange a couple of messages, and then NamedPipeClientStream closing, while NamedPipeServerStream recreated and continue listening for the client pipes. (I couldn't make a working async Server Pipe, so this is some kind of dog-nail)

The client-server interaction works fine during my client's streams launched from normal user sessions.

But there are a situation when Client pipe is launched from session 0 on Win7 and win2008 server. When this happens I had an error in Client stream:

"Access to the path is denied"

What is the problem? How to avoid it?

Sorry I can't tell you more info about exception. Only I have is this message in log. And I can't debug my program from zero session, can I?

The server stream code:

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);

Maybe something is wrong with security settings?

And the client code:

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..
    }
    //...
}

The server is launched as windows service under LocalSystem. The client - is a simple console application. It's launched by another application launched from LocalSystem service.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Looks like the problem was in security settings here:

System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null);

Should be :

System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);

Thanks microsoft communnity


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...