When a file is downloaded from the Internet or other external sources,
Windows may assign a zone identifier to the file using an alternate data
stream named Zone.Identifier. This metadata helps determine
how the system treats the file with respect to security, such as whether
to prompt the user with a warning before opening it.
The GetFileZoneInfo method retrieves the zone ID associated
with the specified local file, allowing an application to determine the
origin and trust level of that file. This can be useful when implementing
additional security measures, auditing downloaded content, or providing
user warnings about potentially untrusted files.
The file name specified by the lpszLocalFile parameter must not
reference a network location. This includes UNC paths (such as
\\server\share\file.txt) and drive letters that are mapped
to network shares. Security zone metadata cannot be read from files on
network volumes because the SMB protocol does not support alternate
data streams.
In addition to the zone ID, this method can optionally return the
source URL used to download the file. This information, if present, is
extracted from the same alternate data stream. Not all files will
include this URL, as it depends on the program or browser that
downloaded the file and whether it preserved this metadata. This
method will not return an error if the URL stored with the security
zone information is not a valid HTTP URL. For example, it's possible
for this method to return zone information with a FTP URL. You can use the
ValidateUrl method to determine if the host URL is a valid
HTTP URL.
Note that not all file systems support alternate data streams. For example,
FAT32 volumes do not support them, and in such cases, zone information
will not be available. Additionally, some applications may remove this
metadata after download or strip it during file copy operations. The
absence of zone information does not guarantee that a file is safe or
originated locally.
If you wish to distinguish between a file which exists without any
zone information, and an error condition where the file does not exist
or could not be accessed, check the last error code. If this method
returns zero and the GetLastError method returns NO_ERROR,
this indicates the file name is valid and it exists, but the
Zone.Identifier alternate data stream does not exist.
For more detailed information about the security zone identifiers,
refer to the SetDefaultZoneId method. To change or remove
the security zone metadata from a local file, use the SetFileZoneInfo
method.