Question

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?

Was it helpful?

Solution

Command echo. > file.exe:Zone.Identifier 1>NUL causes redirection of echo. 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 by echo command by itself.

The solution is to devide the command into two phases by using brackets:

(echo. > file.exe:Zone.Identifier) 2>NUL

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top