Question

How can I set up a Powershell named pipe to be available to all users on the local computer?

I'm writing a small Powershell script and I need to be able to have any user on the local computer be able to write to a named pipe that will be consumed by this script.

I can get the pipe set up with the following:

$pipe=new-object System.IO.Pipes.NamedPipeServerStream("\\.\pipe\mypipe")
$pipe.WaitForConnection()  
$sr = new-object System.IO.StreamReader($pipe)
while (($cmd= $sr.ReadLine()) -ne 'exit') 
....

I'm not sure how to use the System.IO.Pipes.PipeSecurity in conjunction with this.

EDIT: I'm using PS v2 if it matters.

EDIT2:

I've made some progress in getting a named pipe security definition created. Still not sure how to bind it.

$PipeSecurity = new-object System.IO.Pipes.PipeSecurity
$AccessRule = New-Object System.IO.Pipes.PipeAccessRule( "Users", "FullControl", "Allow" )
$PipeSecurity.AddAccessRule($AccessRule)
$pipe=new-object System.IO.Pipes.NamedPipeServerStream("\\.\pipe\mypipe");
$pipe.SetAccessControl( $PipeSecurity ) 
Was it helpful?

Solution

You need to use the right constructor, that property can't be set afterwards. This will do the trick:

$PipeSecurity = new-object System.IO.Pipes.PipeSecurity
$AccessRule = New-Object System.IO.Pipes.PipeAccessRule( "Users", "FullControl", "Allow" )
$PipeSecurity.AddAccessRule($AccessRule)
$pipe=new-object System.IO.Pipes.NamedPipeServerStream("p","In",100, "Byte", "Asynchronous", 32768, 32768, $PipeSecurity);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top