命名管道名称可以带有反斜杠吗? [英] Can named pipe names have backslashes?

查看:111
本文介绍了命名管道名称可以带有反斜杠吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 MSDN

[管道名称]必须具有 格式如下:

[The pipe name] must have the following form:

\\.\pipe\pipename

名称的管道名称部分可以 包括除 反斜杠,包括数字和 特殊的角色.整个管道 名称字符串最多可以为256个 长字符.管道名称不是 区分大小写.

The pipename part of the name can include any character other than a backslash, including numbers and special characters. The entire pipe name string can be up to 256 characters long. Pipe names are not case sensitive.

但是在很多例子中,我看到了带有反斜杠的命名管道名称.例如,SQL Server的标准管道名称为\\.\pipe\sql\query.

But there are plenty of examples where I've seen named pipe names with backslashes in them. For example, the standard pipe name for SQL Server is \\.\pipe\sql\query.

运行SysInternals中的 PipeList 可以发现我的机器上有很多管道,其中名称包含反斜杠.

Running PipeList from SysInternals reveals plenty of pipes on my machine where the name includes a backslash.

那么,管道名称中是否可以包含反斜杠?

So, can a pipe name have a backslash in it or not?

我问是因为我正在创建一个包含多个名称如下的管道的服务:

I ask because I was creating a service with several pipes with names like this:

\\.\pipe\MyApp
\\.\pipe\MyApp\0
\\.\pipe\MyApp\1
\\.\pipe\MyApp\2

创建第一个管道后,创建其他管道将失败,并显示Windows错误123(ERROR_INVALID_NAME).如果我跳过创建第一个管道,则所有其他管道(名称中带有反斜杠字符)都可以正常工作.

After the first pipe was created, creating the other pipes would fail with Windows error 123 (ERROR_INVALID_NAME). If I skipped creating the first pipe, all the others, with the backslash character in the name, would work just fine.

似乎管道是分层的,就像文件系统一样,如果您有一个具有特定名称的管道,则该名称将不再用作其他管道的文件夹"或容器.

It appears that pipes are hierarchical like the file system, and if you have a pipe with a particular name, that name can no longer be used as a "folder" or container for other pipes.

当试图解决这个问题时,我遇到了 MSDN 文章,现在正在质疑我是否应该使用反斜杠.

When trying to figure this out, I came across the MSDN article and am now questioning whether I should be using backslashes at all.

有什么建议吗?

推荐答案

虽然这似乎是未记录的行为,但至少是一致的.只是不要创建与文件夹"同名的管道. Windows在内部将命名管道实现为文件系统.但是,请记住,恶意应用程序可能会创建\.\ pipe \ MyApp管道并导致您的应用程序失败.考虑到使用反斜杠的唯一好处是纯粹的语义,我建议改用下划线或其他字符.

While this appears to be undocumented behavior, it is at least consistent. Just don't create a pipe with the same name as a 'folder'. Windows implements named pipes as a filesystem internally. However also keep in mind that a malicious application could create a \.\pipe\MyApp pipe and cause your app to fail. Considering the only benefits of using the backslash are purely semantic, I would recommend using an underscore or other character instead.

这篇关于命名管道名称可以带有反斜杠吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆