如何在Windows中获取所有打开的命名管道列表?

Dou*_* T. 78 windows winapi pipe

有没有一种简单的方法来测试您的命名管道是否正常工作?我想确保我从我的应用程序发送的数据实际上是发送的.是否有一种快速简便的方法来获取所有命名管道的列表?

Rob*_*ker 85

您可以使用sysinternals中的Process Explorer查看这些内容.使用"查找 - >查找句柄或DLL ..."选项并输入模式"\ Device\NamedPipe \".它将显示哪些进程具有哪些管道打开.

  • 为了避免可能的异常 - 正如在其他答案中提到的那样 - 你可以使用我的解决方案,这个解决方案更低级别但是就像魅力一样工作,即使命名管道名称包含文件名的无效字符.请参阅http://stackoverflow.com/questions/25109491/how-can-i-get-a-list-of-all-open-named-pipes-in-windows-and-avoiding-possible-ex/25126943# 25126943 (2认同)
  • 使用来自 SysInternals 的 `pipelist.exe` 更简单,但它只是命令行。 (2认同)

And*_*erd 61

在Windows Powershell控制台中,键入

[System.IO.Directory]::GetFiles("\\.\\pipe\\")
Run Code Online (Sandbox Code Playgroud)


如果您的操作系统版本大于Windows 7,您也可以输入

get-childitem \\.\pipe\
Run Code Online (Sandbox Code Playgroud)

  • 在 Windows 10 (20H2) 上,get-childitem 变体以某种方式适用于 Powershell 5,但不适用于 Powershell 7。 (4认同)
  • 您可能要考虑以管理员身份打开Powershell (2认同)
  • 您也可以使用 get-childitem \\.\pipe\ (2认同)
  • @Chih-HsuanYen - [这是一个错误](https://github.com/PowerShell/PowerShell/issues/11898)。这是解决方法:`[System.IO.Directory]::EnumerateFiles('\\.\pipe\')` (2认同)

小智 57

请尝试以下方法:

String[] listOfPipes = System.IO.Directory.GetFiles(@"\\.\pipe\");
Run Code Online (Sandbox Code Playgroud)

  • 你错过了一个斜线.string [] listOfPipes = System.IO.Directory.GetFiles(@"\\.\ pipe \"); (6认同)
  • 我们在Windows 10上遇到了这个方法的问题 - 得到错误"第二个路径片段不能是驱动器或UNC名称.参数名称:path2" (5认同)
  • @Kevin"\\.\"表示"这台机器",按照https://msdn.microsoft.com/en-US/en-en/library/windows/desktop/aa365783(v=vs.85).aspx (2认同)

小智 41

使用Sysinternals中的pipelist.exe.

  • 另请参阅 sysinternals 中的 handle.exe,它将显示几乎所有具有打开句柄的内容。 (2认同)

小智 16

C#:

String[] listOfPipes = System.IO.Directory.GetFiles(@"\\.\pipe\");
Run Code Online (Sandbox Code Playgroud)


小智 13

我偶然发现Chrome中的一个功能,它将通过导航到"file://.//pipe//"列出所有打开的命名管道

因为我似乎无法找到任何参考,这对我非常有帮助,我想我可能会分享.


Con*_*dis 12

CMD提示时:

>ver

Microsoft Windows [Version 10.0.18362.476]

>dir \\.\pipe\\
Run Code Online (Sandbox Code Playgroud)


小智 7

第二个管道在提交时由此网站解释...开头需要两个反斜杠.因此,请确保使用System.IO.Directory.GetFiles(@"\\.\ pipe \").

请注意,我已经看到此函数调用抛出"路径中的非法字符".当我的机器上的一个管道有无效字符时出现异常.PipleList.exe工作正常,所以它似乎是MS的.net代码中的一个错误.