批处理文件检测是否可以写入 NTFS 备用流
背景
在 Windows 7 中,当从 Internet 下载文件时,某些浏览器(例如 IE 和 Firefox)会将其标记为来自 Internet。这在文件的属性对话框中很明显,该对话框将在属性窗口底部显示一条消息和一个“取消阻止”按钮。
此属性作为备用流存储在 NTFS 文件系统上 - 具体来说,是一个名为“Zone.Identifier”的流。因此,对于被阻止的文件,您可以运行命令 more < file.exe:Zone.Identifier
并且您会得到输出:
[ZoneTransfer]
ZoneId=3
您可以使用命令 echo 清除此数据。 > file.exe:Zone.Identifier
。这将仅用一个空行覆盖上述数据,并且虽然文件中仍然存在 Zone.Identifier
流,但如属性对话框所确认的,该文件不再“被阻止”。
问题
FAT32 文件系统显然没有 NTFS 备用流;因此,命令回显。 > file.exe:Zone.Identifier
给出输出:
The filename, directory name, or volume label syntax is incorrect.
这是输出到 stdout,因此在末尾添加 2>NUL 不会抑制它。在末尾添加 1>NUL 确实会抑制它,但它也会抑制该命令执行任何有用的操作;也就是说,如果您运行 echo. > file.exe:Zone.Identifier 1>NUL,Zone.Identifier
流保留。
如何运行命令 echo. > file.exe:Zone.Identifier
在 NTFS 上成功,并在 FAT32 上抑制其错误输出?
Background
In Windows 7, when a file is downloaded from the internet, some browsers (e.g. IE and Firefox) flag it as coming from the internet. This is apparent in the properties dialog of the file, which will show a message and an "Unblock" button at the bottom of the properties window.
This property is stored as an alternate stream on the NTFS filesystem - specifically, a stream named "Zone.Identifier". So on a blocked file, you can run the command more < file.exe:Zone.Identifier
and you get the output:
[ZoneTransfer]
ZoneId=3
You can clear this data with the command echo. > file.exe:Zone.Identifier
. This overwrites the above data with simply a blank line, and while the Zone.Identifier
stream still exists on the file, the file is no longer "blocked" as confirmed by the properties dialog.
Problem
FAT32 file systems obviously don't have NTFS alternate streams; so, the command echo. > file.exe:Zone.Identifier
gives the output:
The filename, directory name, or volume label syntax is incorrect.
This is output to stdout, so adding 2>NUL on the end does not suppress it. Adding 1>NUL to the end DOES suppress it, however it also suppresses the command from doing anything useful; that is, if you run echo. > file.exe:Zone.Identifier 1>NUL
, the Zone.Identifier
stream remains.
How can I run the command echo. > file.exe:Zone.Identifier
successfully on NTFS, and suppress its error output on FAT32?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
命令
回显。 > file.exe:Zone.Identifier 1>NUL
导致echo.
重定向到 NUL,第一个重定向将被忽略。添加
2>NUL
会导致 echo 的 stderr 重定向到 NUL。您试图避免的消息是通过失败的重定向而不是通过 echo 命令本身打印到 stderr 的。解决方案是使用括号将命令分为两个阶段:
这将导致
echo.
首先执行,并将其输出重定向到备用文件流。如果尝试写入 FAT 文件系统上的替代文件流失败,则其输出到 stderr 将被重定向到 NUL。Command
echo. > file.exe:Zone.Identifier 1>NUL
causes redirection ofecho.
to NUL, the first redirection is ignored.Adding
2>NUL
causes redirection of echo's stderr to NUL. The message you are trying to avoid is printed to stderr by failed redirection and not byecho
command by itself.The solution is to devide the command into two phases by using brackets:
This will cause
echo.
to be executed first and its output redirected to alternative file stream. If trying to write to alternative file stream on FAT filesystem failes, then it's output to stderr will be redirected to NUL.